Skip to content

Commit

Permalink
Support OUT_DIR located in \\?\ path on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 14, 2024
1 parent c7bc274 commit cfafcd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\"");
}
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cfafcd5

Please sign in to comment.