39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use std::env;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
|
|
// 设置 Windows 应用程序图标
|
|
let icon_path = PathBuf::from("unlock.ico");
|
|
if icon_path.exists() {
|
|
// 创建 .rc 文件
|
|
let rc_content = format!(r#"1 ICON "{}""#, icon_path.canonicalize().unwrap().display());
|
|
let rc_path = out_dir.join("app.rc");
|
|
std::fs::write(&rc_path, rc_content).unwrap();
|
|
|
|
// 编译资源文件
|
|
let res_path = out_dir.join("app.res");
|
|
|
|
// 使用 windres (MinGW) 编译资源
|
|
let status = std::process::Command::new("windres")
|
|
.args(&[
|
|
rc_path.to_str().unwrap(),
|
|
"-O",
|
|
"coff",
|
|
"-o",
|
|
res_path.to_str().unwrap(),
|
|
])
|
|
.status();
|
|
|
|
if let Ok(status) = status {
|
|
if status.success() {
|
|
println!("cargo:rustc-link-arg={}", res_path.display());
|
|
}
|
|
}
|
|
}
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
println!("cargo:rerun-if-changed=unlock.ico");
|
|
}
|