|
| 1 | +//! This embeds a "manifest" - a special XML document - into the uv binary on Windows builds. |
| 2 | +//! It includes reasonable defaults for Windows binaries: |
| 3 | +//! - "System" codepage to retain backwards compatibility with previous uv releases. |
| 4 | +//! We can set to the utf-8 codepage in a future breaking release which lets us use the |
| 5 | +//! *A versions of Windows API functions without utf-16 conversion. |
| 6 | +//! - long path awareness allows paths longer than 260 characters in Windows operations. |
| 7 | +//! - Windows 10+ support to avoid legacy compat layers from being potentially applied by not |
| 8 | +//! specifying any. We don't declare `Windows7..=Windows10` as toolchain support for Windows 7 |
| 9 | +//! is tier 3, and it's better to let Windows apply the appropriate compatibility layer. |
| 10 | +//! - Other settings such as execution level are standard defaults. |
| 11 | +//! See <https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests> |
| 12 | +use embed_manifest::manifest::{ActiveCodePage, ExecutionLevel, Setting, SupportedOS}; |
| 13 | +use embed_manifest::{embed_manifest, empty_manifest}; |
| 14 | + |
| 15 | +fn main() { |
| 16 | + if std::env::var_os("CARGO_CFG_WINDOWS").is_some() { |
| 17 | + let [major, minor, patch] = uv_version::version() |
| 18 | + .splitn(3, '.') |
| 19 | + .map(str::parse) |
| 20 | + .collect::<Result<Vec<u16>, _>>() |
| 21 | + .ok() |
| 22 | + .and_then(|v| v.try_into().ok()) |
| 23 | + .expect("uv version must be in x.y.z format"); |
| 24 | + let manifest = empty_manifest() |
| 25 | + .name("uv") |
| 26 | + .version(major, minor, patch, 0) |
| 27 | + .active_code_page(ActiveCodePage::System) |
| 28 | + // Includes Windows 10 and 11, and Windows Server 2016, 2019 and 2022 |
| 29 | + .supported_os(SupportedOS::Windows10..=SupportedOS::Windows10) |
| 30 | + .requested_execution_level(ExecutionLevel::AsInvoker) |
| 31 | + .long_path_aware(Setting::Enabled); |
| 32 | + embed_manifest(manifest).expect("unable to embed manifest"); |
| 33 | + println!("cargo:rerun-if-changed=build.rs"); |
| 34 | + } |
| 35 | +} |
0 commit comments