51 lines
2.3 KiB
Rust
51 lines
2.3 KiB
Rust
// Embed the application icon and EXE metadata on Windows.
|
|
//
|
|
// The icon (`resources/icon.ico`, multi-frame: 16/32/48/64/128/256) ends
|
|
// up as the executable's IDI_ICON1 resource — that's what Explorer, the
|
|
// taskbar, Alt+Tab, the Task Manager, and the title-bar of any dialog
|
|
// hosted by this process pick up. Regenerate the .ico from the source
|
|
// PNG by running `python3 resources/build_ico.py`.
|
|
//
|
|
// The version-info block populates the "Details" tab in the EXE's
|
|
// Properties dialog (ProductName / FileDescription / etc.). winres
|
|
// derives FileVersion / ProductVersion from CARGO_PKG_VERSION
|
|
// automatically.
|
|
//
|
|
// We gate on `CARGO_CFG_TARGET_OS` (the *target* OS, not the host) so a
|
|
// cross-compile from Linux/macOS to Windows still embeds the icon. winres
|
|
// inspects the active linker/toolchain (windres for GNU, rc.exe for MSVC)
|
|
// when invoked.
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
println!("cargo:rerun-if-changed=resources/icon.ico");
|
|
// winres derives FileVersion / ProductVersion from `CARGO_PKG_VERSION`,
|
|
// which is sourced from `Cargo.toml`. Without this directive, cargo
|
|
// happily skips the build script when only the version field changed
|
|
// (build.rs and the .ico are byte-identical), and the resulting EXE
|
|
// ships with stale "FileVersion" / "ProductVersion" properties — the
|
|
// binary itself is the new build, but Explorer's Properties dialog
|
|
// and any Authenticode tooling that reads the resource block see the
|
|
// previous version. Forcing a re-run on Cargo.toml changes is cheap
|
|
// (winres compile is sub-second) and bulletproof.
|
|
println!("cargo:rerun-if-changed=Cargo.toml");
|
|
|
|
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
|
if target_os != "windows" {
|
|
return;
|
|
}
|
|
|
|
let mut res = winres::WindowsResource::new();
|
|
res.set_icon("resources/icon.ico")
|
|
.set("ProductName", "HelloAgent")
|
|
.set("FileDescription", "HelloAgent — RustDesk-protocol support agent")
|
|
.set("CompanyName", "cStudio GmbH")
|
|
.set("LegalCopyright", "Copyright © 2026 cStudio GmbH")
|
|
.set("OriginalFilename", "hello-agent.exe")
|
|
.set("InternalName", "hello-agent");
|
|
if let Err(e) = res.compile() {
|
|
eprintln!("winres: failed to compile icon resource: {e}");
|
|
std::process::exit(1);
|
|
}
|
|
}
|