Skip to content

Commit

Permalink
Merge pull request #271 from dtolnay/windows
Browse files Browse the repository at this point in the history
Support OUT_DIR located in `\\?\` path on Windows
  • Loading branch information
dtolnay authored May 14, 2024
2 parents 02e6117 + 7c8c364 commit 742c6b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn main() -> io::Result<()> {
println!("cargo:rerun-if-changed=src/tests");

println!("cargo:rustc-check-cfg=cfg(trybuild_no_target)");
println!("cargo:rustc-check-cfg=cfg(host_os, values(\"windows\"))");

let out_dir = env::var_os("OUT_DIR").unwrap();
let target = env::var("TARGET").ok();
Expand All @@ -15,5 +16,12 @@ fn main() -> io::Result<()> {
Some(target) => format!(r#"Some("{}")"#, target.escape_debug()),
None => "None".to_owned(),
};
fs::write(path, value)
fs::write(path, value)?;

let host = env::var_os("HOST").unwrap();
if let Some("windows") = host.to_str().unwrap().split('-').nth(2) {
println!("cargo:rustc-cfg=host_os=\"windows\"");
}

Ok(())
}
4 changes: 4 additions & 0 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ fn features(project: &Project) -> Vec<String> {
}

fn target() -> Vec<&'static str> {
#[cfg(not(host_os = "windows"))]
const TARGET: Option<&str> = include!(concat!(env!("OUT_DIR"), "/target"));

#[cfg(host_os = "windows")]
const TARGET: Option<&str> = include!(concat!(env!("OUT_DIR"), "\\target"));

// When --target flag is passed, cargo does not pass RUSTFLAGS to rustc when
// building proc-macro and build script even if the host and target triples
// are the same. Therefore, if we always pass --target to cargo, tools such
Expand Down

0 comments on commit 742c6b3

Please sign in to comment.