diff --git a/bff-cli/build.rs b/bff-cli/build.rs index 517ae19..d16f6a9 100644 --- a/bff-cli/build.rs +++ b/bff-cli/build.rs @@ -1,3 +1,5 @@ +use std::env; + use shadow_rs::{BuildPattern, ShadowBuilder}; fn main() { @@ -5,4 +7,30 @@ fn main() { .build_pattern(BuildPattern::Lazy) .build() .unwrap(); + + set_windows_exe_options(); +} + +// https://github.com/rust-lang/rust/commit/5e6bb83268518dcd74c96b5504f485b71e604e4c +// https://github.com/BurntSushi/ripgrep/commit/db6bb21a629d5b1ec1bfe89c693b280497c9eedc +// Add a manifest file to bff-cli.exe. +fn set_windows_exe_options() { + static MANIFEST: &str = "pkg/windows/Manifest.xml"; + + let Ok(target_os) = env::var("CARGO_CFG_TARGET_OS") else { return }; + let Ok(target_env) = env::var("CARGO_CFG_TARGET_ENV") else { return }; + if !(target_os == "windows" && target_env == "msvc") { + return; + } + + let mut manifest = env::current_dir().unwrap(); + manifest.push(MANIFEST); + let manifest = manifest.to_str().unwrap(); + + println!("cargo:rerun-if-changed={}", MANIFEST); + // Embed the Windows application manifest file. + println!("cargo:rustc-link-arg-bin=bff-cli=/MANIFEST:EMBED"); + println!("cargo:rustc-link-arg-bin=bff-cli=/MANIFESTINPUT:{manifest}"); + // Turn linker warnings into errors. + println!("cargo:rustc-link-arg-bin=bff-cli=/WX"); } diff --git a/bff-cli/pkg/windows/Manifest.xml b/bff-cli/pkg/windows/Manifest.xml new file mode 100644 index 0000000..b6f0e70 --- /dev/null +++ b/bff-cli/pkg/windows/Manifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + UTF-8 + + + + + + true + + +