-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.rs
68 lines (57 loc) · 2.03 KB
/
build.rs
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
use std::env;
use std::fs;
use std::path::PathBuf;
extern crate winres;
use winres::VersionInfo;
fn main() {
// only run if target os is windows
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() != "windows" {
println!("cargo:warning={:#?}", "This build script is only for windows target, skipping...");
return;
}
for (key, value) in env::vars() {
println!("cargo:ingo={}: {}", key, value);
}
// 获取profile env
let profile = env::var("PROFILE").unwrap();
let out_dir = "target".to_string() + "/" + &profile;
let _ = fs::create_dir_all(&out_dir);
println!("Output directory: {:?}", out_dir);
println!("cargo::rerun-if-changed=models/model_training.onnx");
println!("cargo::rerun-if-changed=models/index_2_word.json");
println!("cargo::rerun-if-changed=config.json");
let files_to_copy = vec![
"models/model_training.onnx",
"models/index_2_word.json",
// "config.json"
];
// 复制每个文件到可执行文件输出目录
for file in files_to_copy {
let file_path = PathBuf::from(file);
let file_name = file_path.file_name().unwrap();
let dest_path = PathBuf::from(&out_dir).join(file_name);
let _ = fs::copy(&file_path, &dest_path).unwrap();
}
let mut res = winres::WindowsResource::new();
// if cfg!(unix) {
// // paths for X64 on archlinux
// res.set_toolkit_path("/usr/x86_64-w64-mingw32/bin");
// // ar tool for mingw in toolkit path
// res.set_ar_path("ar");
// // windres tool
// res.set_windres_path("/usr/bin/x86_64-w64-mingw32-windres");
// }
let mut version = 0;
version |= 4 << 48;
version |= 6 << 32;
version |= 0 << 16;
version |= 71;
res.set_version_info(VersionInfo::FILEVERSION, version)
.set_version_info(VersionInfo::PRODUCTVERSION, version)
.set_manifest_file("manifest.xml");
if let Err(e) = res.compile() {
eprintln!("{}", e);
std::process::exit(1);
}
// }
}