1 | use std::env; |
2 | |
3 | fn main() { |
4 | let target_os: Result = env::var(key:"CARGO_CFG_TARGET_OS" ); |
5 | let target_env: Result = env::var(key:"CARGO_CFG_TARGET_ENV" ); |
6 | if Ok("windows" ) == target_os.as_deref() && Ok("msvc" ) == target_env.as_deref() { |
7 | set_windows_exe_options(); |
8 | } else { |
9 | // Avoid rerunning the build script every time. |
10 | println!("cargo:rerun-if-changed=build.rs" ); |
11 | } |
12 | } |
13 | |
14 | // Add a manifest file to rustc.exe. |
15 | fn set_windows_exe_options() { |
16 | static WINDOWS_MANIFEST_FILE: &str = "Windows Manifest.xml" ; |
17 | |
18 | let mut manifest: PathBuf = env::current_dir().unwrap(); |
19 | manifest.push(path:WINDOWS_MANIFEST_FILE); |
20 | |
21 | println!("cargo:rerun-if-changed= {WINDOWS_MANIFEST_FILE}" ); |
22 | // Embed the Windows application manifest file. |
23 | println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFEST:EMBED" ); |
24 | println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFESTINPUT: {}" , manifest.to_str().unwrap()); |
25 | // Turn linker warnings into errors. |
26 | println!("cargo:rustc-link-arg-bin=rustc-main=/WX" ); |
27 | } |
28 | |