initial commit
This commit is contained in:
45
build.rs
Normal file
45
build.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let ico_path = PathBuf::from("location.ico");
|
||||
|
||||
if !ico_path.exists() {
|
||||
println!(
|
||||
"cargo:warning=location.ico 不存在,将不嵌入图标。请将图标文件放入项目根目录。"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
println!("cargo:rerun-if-changed=location.ico");
|
||||
println!("cargo:rerun-if-changed=icon.rc");
|
||||
|
||||
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
let res_output = out_dir.join("icon.res");
|
||||
|
||||
let windres_path = find_windres();
|
||||
let status = Command::new(&windres_path)
|
||||
.args([
|
||||
"icon.rc",
|
||||
"-O", "coff",
|
||||
"-o",
|
||||
])
|
||||
.arg(&res_output)
|
||||
.status()
|
||||
.expect("执行 windres 失败");
|
||||
|
||||
if !status.success() {
|
||||
panic!("windres 编译资源文件失败");
|
||||
}
|
||||
|
||||
println!("cargo:rustc-link-arg={}", res_output.display());
|
||||
}
|
||||
|
||||
fn find_windres() -> PathBuf {
|
||||
let mingw_windres = PathBuf::from("C:\\msys64\\mingw64\\bin\\windres.exe");
|
||||
if mingw_windres.exists() {
|
||||
return mingw_windres;
|
||||
}
|
||||
|
||||
PathBuf::from("windres")
|
||||
}
|
||||
Reference in New Issue
Block a user