32 lines
1.8 KiB
Rust
32 lines
1.8 KiB
Rust
fn main() {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
windows_resource();
|
|
}
|
|
|
|
/// Windows: embed the icon and version resource into audiphi.exe (needs mingw's windres; skipped without it).
|
|
fn windows_resource() {
|
|
println!("cargo:rerun-if-changed=packaging/audiphi.ico");
|
|
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
|
return;
|
|
}
|
|
let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
|
let ver = std::env::var("CARGO_PKG_VERSION").unwrap();
|
|
let nums: Vec<&str> = ver.split('.').collect();
|
|
let comma = format!("{},{},{},0", nums[0], nums.get(1).unwrap_or(&"0"), nums.get(2).unwrap_or(&"0"));
|
|
let ico = std::fs::canonicalize("packaging/audiphi.ico").unwrap().to_string_lossy().replace('\\', "/");
|
|
let rc = format!(
|
|
"1 ICON \"{ico}\"\n\
|
|
1 VERSIONINFO\nFILEVERSION {comma}\nPRODUCTVERSION {comma}\nBEGIN\n BLOCK \"StringFileInfo\"\n BEGIN\n BLOCK \"040904b0\"\n BEGIN\n\
|
|
\x20 VALUE \"ProductName\", \"Audiphi\"\n VALUE \"FileDescription\", \"Audiphi music downloader and player\"\n VALUE \"FileVersion\", \"{ver}\"\n VALUE \"ProductVersion\", \"{ver}\"\n VALUE \"OriginalFilename\", \"audiphi.exe\"\n\
|
|
\x20 END\n END\n BLOCK \"VarFileInfo\"\n BEGIN\n VALUE \"Translation\", 0x0409, 1200\n END\nEND\n"
|
|
);
|
|
let rc_path = out.join("audiphi.rc");
|
|
std::fs::write(&rc_path, rc).unwrap();
|
|
let obj = out.join("audiphi_res.o");
|
|
let ok = std::process::Command::new("x86_64-w64-mingw32-windres").arg(&rc_path).arg(&obj).status().map(|s| s.success()).unwrap_or(false);
|
|
if ok {
|
|
println!("cargo:rustc-link-arg-bins={}", obj.display());
|
|
} else {
|
|
println!("cargo:warning=windres not available: audiphi.exe has no icon/version resource");
|
|
}
|
|
}
|