From cfafcd5906e6020ae67014e33a84446824301c95 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 14 May 2024 13:18:11 -0700 Subject: [PATCH] Support OUT_DIR located in \\?\ path on Windows --- build/build.rs | 6 ++++++ src/lib.rs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/build/build.rs b/build/build.rs index 05f88dc..c1355f2 100644 --- a/build/build.rs +++ b/build/build.rs @@ -75,10 +75,16 @@ fn main() { if version.minor >= 80 { println!("cargo:rustc-check-cfg=cfg(cfg_macro_not_allowed)"); + println!("cargo:rustc-check-cfg=cfg(host_os, values(\"windows\"))"); } let version = format!("{:#?}\n", version); let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR not set"); let out_file = Path::new(&out_dir).join("version.expr"); fs::write(out_file, version).expect("failed to write version.expr"); + + let host = env::var_os("HOST").expect("HOST not set"); + if let Some("windows") = host.to_str().unwrap().split('-').nth(2) { + println!("cargo:rustc-cfg=host_os=\"windows\""); + } } diff --git a/src/lib.rs b/src/lib.rs index 4802003..47a0370 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -183,8 +183,12 @@ use crate::error::Error; use crate::version::Version; use proc_macro::TokenStream; +#[cfg(not(host_os = "windows"))] const RUSTVERSION: Version = include!(concat!(env!("OUT_DIR"), "/version.expr")); +#[cfg(host_os = "windows")] +const RUSTVERSION: Version = include!(concat!(env!("OUT_DIR"), "\\version.expr")); + #[proc_macro_attribute] pub fn stable(args: TokenStream, input: TokenStream) -> TokenStream { expand::cfg("stable", args, input)