Fix build.rs to run windres on all platforms

This commit is contained in:
2026-06-01 05:48:12 +02:00
parent 2549c74a94
commit 6174f53951
+19 -22
View File
@@ -1,27 +1,24 @@
fn main() {
// Embed icon on Windows (via windres for cross-compilation support)
#[cfg(target_os = "windows")]
{
let out_dir = std::env::var("OUT_DIR").unwrap();
let rc_path = "resources/app.rc";
let res_path = format!("{}/app.res", out_dir);
let status = std::process::Command::new("x86_64-w64-mingw32-windres")
.args([rc_path, "-O", "coff", "-o", &res_path])
.status();
if let Ok(s) = status {
if s.success() {
println!("cargo:rustc-link-arg={}", res_path);
return;
}
}
// Fallback: try plain windres
let status = std::process::Command::new("windres")
.args([rc_path, "-O", "coff", "-o", &res_path])
.status();
if let Ok(s) = status {
if s.success() {
println!("cargo:rustc-link-arg={}", res_path);
let out_dir = std::env::var("OUT_DIR").unwrap();
let rc_path = "resources/app.rc";
let res_path = format!("{}/app.res", out_dir);
// Try cross-compile windres first, then native windres
let compiled = || -> bool {
for windres in &["x86_64-w64-mingw32-windres", "windres"] {
if std::process::Command::new(windres)
.args(["-I", ".", rc_path, "-O", "coff", "-o", &res_path])
.status()
.map(|s| s.success())
.unwrap_or(false)
{
return true;
}
}
false
};
if compiled() {
println!("cargo:rustc-link-arg={}", res_path);
}
}