4 let target_os = env::var("CARGO_CFG_TARGET_OS");
5 let target_env = env::var("CARGO_CFG_TARGET_ENV");
6 if Ok("windows") == target_os.as_deref() && Ok("msvc") == target_env.as_deref() {
7 set_windows_exe_options();
9 // Avoid rerunning the build script every time.
10 println!("cargo:rerun-if-changed=build.rs");
14 // Add a manifest file to rustc.exe.
15 fn set_windows_exe_options() {
16 static WINDOWS_MANIFEST_FILE: &str = "Windows Manifest.xml";
18 let mut manifest = env::current_dir().unwrap();
19 manifest.push(WINDOWS_MANIFEST_FILE);
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");