Files
advotracker/advotracker_client/build.rs-winres
2021-05-21 12:46:33 +02:00

53 lines
1.8 KiB
Plaintext

/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
use std::env;
use std::error::Error;
use winres::{WindowsResource, VersionInfo};
fn add_icon_to_bin_when_building_for_win(icon_path: &str) -> Result<(), Box<dyn Error>> {
if env::var("CARGO_CFG_TARGET_FAMILY")? == "windows" {
let mut res = WindowsResource::new();
let target_env = std::env::var("CARGO_CFG_TARGET_ENV")?;
match target_env.as_str() {
"gnu" => res
.set_ar_path("x86_64-w64-mingw32-ar")
.set_windres_path("x86_64-w64-mingw32-windres")
.set_toolkit_path(".")
.set_icon(icon_path)
.set_version_info(VersionInfo::PRODUCTVERSION, 0x0000000100050003),
"msvc" => res.set_icon(icon_path),
_ => panic!("Unsupported env: {}", target_env),
};
res.compile()?;
}
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
add_icon_to_bin_when_building_for_win("./assets/icons/advotracker/advotracker.ico")
}
// // only build for windows
// fn main() {
// if cfg!(target_os = "windows") {
// println!("You are building for windows!");
// // only build the resource for release builds
// // as calling rc.exe might be slow
// //if std::env::var("PROFILE").unwrap() == "release" { ]
// let mut res = winres::WindowsResource::new();
// res.set_icon("advotracker.ico")
// .set("InternalName", "ADVOTRACKER.EXE")
// // manually set version 0.1.5.2
// .set_version_info(winres::VersionInfo::PRODUCTVERSION, 0x0000000100050003);
// res.compile().unwrap();
// } else {
// println!("not windows, so no resource icon needed!");
// }
// }