-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbuild.rs
More file actions
69 lines (58 loc) · 2.27 KB
/
build.rs
File metadata and controls
69 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Moosync
// Copyright (C) 2024, 2025 Moosync <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use leptos_i18n_build::{Options, TranslationsInfos};
use std::{
env, fs,
path::{Path, PathBuf},
};
fn find_function_details_json(target_dir: &Path) -> Option<PathBuf> {
for entry in fs::read_dir(target_dir).ok()? {
let entry = entry.ok()?;
let path = entry.path();
if path.is_dir() {
if let Some(found) = find_function_details_json(&path) {
return Some(found);
}
} else if path.ends_with("function_details.json") {
return Some(path);
}
}
None
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=Cargo.toml");
let i18n_mod_directory = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("i18n");
let options = Options::default().interpolate_display(true);
let translations_infos = TranslationsInfos::parse(options).unwrap();
translations_infos.rerun_if_locales_changed();
translations_infos
.generate_i18n_module(i18n_mod_directory)
.unwrap();
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not set");
let manifest_dir = Path::new(&manifest_dir);
if let Some(file_path) = find_function_details_json(manifest_dir.join("src-tauri").as_path()) {
println!(
"cargo:rustc-env=TAURI_INVOKE_PROC_DIR={}",
file_path.to_string_lossy()
);
} else {
println!("cargo:warning=Could not find function_details.json");
}
if cfg!(debug_assertions) {
println!("cargo:rustc-cfg=erase_components");
}
}