From 6174f5395120f1b07666604288c303e7b1583f16 Mon Sep 17 00:00:00 2001 From: forkless Date: Mon, 1 Jun 2026 05:48:12 +0200 Subject: [PATCH] Fix build.rs to run windres on all platforms --- build.rs | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/build.rs b/build.rs index 4d29842..53f694d 100644 --- a/build.rs +++ b/build.rs @@ -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); } }