fn main() { println!("cargo:rerun-if-changed=assets/icon.ico"); println!("cargo:rerun-if-changed=build.rs"); let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); if target_os == "windows" { let out_dir = std::env::var("OUT_DIR").unwrap(); let rc_path = format!("{}/sanctum.rc", out_dir); let res_path = format!("{}/sanctum.res", out_dir); let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); let ico_path = format!("{}/assets/icon.ico", manifest_dir).replace('\\', "/"); if std::path::Path::new(&ico_path).exists() { let rc_content = format!("1 ICON \"{}\"\n", ico_path); if std::fs::write(&rc_path, rc_content).is_ok() { let mut compiled = false; for tool in ["windres", "x86_64-w64-mingw32-windres"] { if let Ok(s) = std::process::Command::new(tool) .args(["-i", &rc_path, "-O", "coff", "-o", &res_path]) .status() { if s.success() { compiled = true; break; } } } if !compiled { if let Ok(s) = std::process::Command::new("zig") .args(["rc", "--", &rc_path, &res_path]) .status() { if s.success() { compiled = true; } } } if compiled { println!("cargo:rustc-link-arg={}", res_path); } } } } }