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

Rely on $TARGET always set during build script execution #291

Merged
merged 1 commit into from
Oct 18, 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
7 changes: 2 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ fn main() -> io::Result<()> {
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();
let target = env::var("TARGET").unwrap();
let path = Path::new(&out_dir).join("target");
let value = match target {
Some(target) => format!(r#"Some("{}")"#, target.escape_debug()),
None => "None".to_owned(),
};
let value = format!(r#""{}""#, target.escape_debug());
fs::write(path, value)?;

let host = env::var_os("HOST").unwrap();
Expand Down
8 changes: 3 additions & 5 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ 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"));
const TARGET: &str = include!(concat!(env!("OUT_DIR"), "/target"));

#[cfg(host_os = "windows")]
const TARGET: Option<&str> = include!(concat!(env!("OUT_DIR"), "\\target"));
const TARGET: &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
Expand All @@ -204,9 +204,7 @@ fn target() -> Vec<&'static str> {
// Therefore, expose a cfg to always treat the target as host.
if cfg!(trybuild_no_target) {
vec![]
} else if let Some(target) = TARGET {
vec!["--target", target]
} else {
vec![]
vec!["--target", TARGET]
}
}
Loading