From 6f7f927acf1fd20acd0694a3aac9394869585180 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 7 Dec 2023 14:24:58 +0000 Subject: [PATCH] Add a windows manifest file This avoids the need for compatibility shims, sets the code page to UTF-8 and enables long path awareness. --- build.rs | 24 ++++++++++++++++++++++++ windows.manifest.xml | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 windows.manifest.xml diff --git a/build.rs b/build.rs index 97678ed1bab..60fda40e323 100644 --- a/build.rs +++ b/build.rs @@ -7,6 +7,7 @@ use std::process::Command; fn main() { commit_info(); compress_man(); + windows_manifest(); // ALLOWED: Accessing environment during build time shouldn't be prohibited. #[allow(clippy::disallowed_methods)] let target = std::env::var("TARGET").unwrap(); @@ -76,3 +77,26 @@ fn commit_info() { println!("cargo:rustc-env=CARGO_COMMIT_SHORT_HASH={}", next()); println!("cargo:rustc-env=CARGO_COMMIT_DATE={}", next()) } + +#[allow(clippy::disallowed_methods)] +fn windows_manifest() { + use std::env; + let target_os = env::var("CARGO_CFG_TARGET_OS"); + let target_env = env::var("CARGO_CFG_TARGET_ENV"); + if Ok("windows") == target_os.as_deref() && Ok("msvc") == target_env.as_deref() { + static WINDOWS_MANIFEST_FILE: &str = "windows.manifest.xml"; + + let mut manifest = env::current_dir().unwrap(); + manifest.push(WINDOWS_MANIFEST_FILE); + + println!("cargo:rerun-if-changed={WINDOWS_MANIFEST_FILE}"); + // Embed the Windows application manifest file. + println!("cargo:rustc-link-arg-bin=cargo=/MANIFEST:EMBED"); + println!( + "cargo:rustc-link-arg-bin=cargo=/MANIFESTINPUT:{}", + manifest.to_str().unwrap() + ); + // Turn linker warnings into errors. + println!("cargo:rustc-link-arg-bin=cargo=/WX"); + } +} diff --git a/windows.manifest.xml b/windows.manifest.xml new file mode 100644 index 00000000000..8a9d5d1b7b9 --- /dev/null +++ b/windows.manifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + UTF-8 + + + + + + true + + +