//! The Windows build carries the app's icon as its resource 1, where GPUI loads its windows' //! icon from (and Explorer, the Start Menu and Settings > Apps show it). The resource compiler //! is LLVM's (`llvm-rc`, in the dev shell), or `rc.exe` on Windows; `PS_GUI_RC` names another. //! (Not `RC`: the dev shell sets that to MinGW's windres, which takes other arguments.) Without //! one the app builds with Windows' default icon, and says so; tools/package.sh refuses that. use std::path::PathBuf; use std::process::Command; fn main() { let icon = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("assets/proxy-suite.ico"); println!("cargo:rerun-if-changed={}", icon.display()); println!("cargo:rerun-if-env-changed=PS_GUI_RC"); if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") { return; } let out = PathBuf::from(std::env::var("OUT_DIR").unwrap()); let rc = out.join("app.rc"); let res = out.join("app.res"); // The resource script's strings are C strings: backslashes doubled. std::fs::write(&rc, format!("1 ICON \"{}\"\n", icon.display().to_string().replace('\\', "\\\\"))).unwrap(); let compiler = std::env::var("PS_GUI_RC").unwrap_or_else(|_| if cfg!(windows) { "rc.exe".into() } else { "llvm-rc".into() }); let mut command = Command::new(&compiler); command.arg("/nologo"); if compiler.contains("llvm-rc") { // Nothing to preprocess, so no C compiler needed for it. command.arg("/no-preprocess"); } match command.arg("/fo").arg(&res).arg(&rc).status() { Ok(s) if s.success() => println!("cargo:rustc-link-arg-bins={}", res.display()), Ok(s) => println!("cargo:warning=the app's icon: {compiler} failed ({s}); building without it"), Err(e) => println!("cargo:warning=the app's icon: no {compiler} ({e}); building without it"), } }