Skip to content

Commit 7c8c364

Browse files
committed
Support OUT_DIR located in \\?\ path on Windows
1 parent 02e6117 commit 7c8c364

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn main() -> io::Result<()> {
77
println!("cargo:rerun-if-changed=src/tests");
88

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

1112
let out_dir = env::var_os("OUT_DIR").unwrap();
1213
let target = env::var("TARGET").ok();
@@ -15,5 +16,12 @@ fn main() -> io::Result<()> {
1516
Some(target) => format!(r#"Some("{}")"#, target.escape_debug()),
1617
None => "None".to_owned(),
1718
};
18-
fs::write(path, value)
19+
fs::write(path, value)?;
20+
21+
let host = env::var_os("HOST").unwrap();
22+
if let Some("windows") = host.to_str().unwrap().split('-').nth(2) {
23+
println!("cargo:rustc-cfg=host_os=\"windows\"");
24+
}
25+
26+
Ok(())
1927
}

src/cargo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,12 @@ fn features(project: &Project) -> Vec<String> {
183183
}
184184

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

189+
#[cfg(host_os = "windows")]
190+
const TARGET: Option<&str> = include!(concat!(env!("OUT_DIR"), "\\target"));
191+
188192
// When --target flag is passed, cargo does not pass RUSTFLAGS to rustc when
189193
// building proc-macro and build script even if the host and target triples
190194
// are the same. Therefore, if we always pass --target to cargo, tools such

0 commit comments

Comments
 (0)