Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OUT_DIR located in \\?\ path on Windows #271

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading