39 lines
1.4 KiB
Rust
39 lines
1.4 KiB
Rust
fn main() {
|
|
let hash = std::process::Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
.unwrap_or_default();
|
|
let hash = hash.trim();
|
|
println!("cargo:rustc-env=GIT_COMMIT={}", if hash.is_empty() { "unknown" } else { hash });
|
|
println!("cargo:rerun-if-changed=.git/HEAD");
|
|
|
|
// Embed Windows icon when cross-compiling for Windows
|
|
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
|
|
// Find windres: prefer arch-prefixed, fall back to plain windres
|
|
let windres = if std::process::Command::new("x86_64-w64-mingw32-windres")
|
|
.arg("--version")
|
|
.output()
|
|
.is_ok()
|
|
{
|
|
"x86_64-w64-mingw32-windres"
|
|
} else {
|
|
"windres"
|
|
};
|
|
|
|
let mut res = winres::WindowsResource::new();
|
|
res.set_icon("../../assets/icon.ico");
|
|
res.set_toolkit_path("/usr");
|
|
res.set_windres_path(windres);
|
|
res.set_ar_path("x86_64-w64-mingw32-ar");
|
|
|
|
match res.compile() {
|
|
Ok(_) => println!("cargo:warning=Icon embedded successfully via {windres}"),
|
|
Err(e) => {
|
|
println!("cargo:warning=winres failed: {e}");
|
|
println!("cargo:warning=windres path used: {windres}");
|
|
}
|
|
}
|
|
}
|
|
}
|