Skip to content

Commit

Permalink
Prioritize RUSTC_LINKER over target->cross-compile-prefix table. (#767)
Browse files Browse the repository at this point in the history
fix #654
  • Loading branch information
dot-asm authored Jan 31, 2023
1 parent 6008cbf commit 9e50fb8
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2864,23 +2864,14 @@ impl Build {
}

fn prefix_for_target(&self, target: &str) -> Option<String> {
// Put aside RUSTC_LINKER's prefix to be used as last resort
let rustc_linker = self.getenv("RUSTC_LINKER").unwrap_or("".to_string());
// let linker_prefix = rustc_linker.strip_suffix("-gcc"); // >=1.45.0
let linker_prefix = if rustc_linker.len() > 4 {
let (prefix, suffix) = rustc_linker.split_at(rustc_linker.len() - 4);
if suffix == "-gcc" {
Some(prefix)
} else {
None
}
} else {
None
};
// Put aside RUSTC_LINKER's prefix to be used as second choice, after CROSS_COMPILE
let linker_prefix = self
.getenv("RUSTC_LINKER")
.and_then(|var| var.strip_suffix("-gcc").map(str::to_string));
// CROSS_COMPILE is of the form: "arm-linux-gnueabi-"
let cc_env = self.getenv("CROSS_COMPILE");
let cross_compile = cc_env.as_ref().map(|s| s.trim_end_matches('-').to_owned());
cross_compile.or(match &target[..] {
cross_compile.or(linker_prefix).or(match &target[..] {
// Note: there is no `aarch64-pc-windows-gnu` target, only `-gnullvm`
"aarch64-pc-windows-gnullvm" => Some("aarch64-w64-mingw32"),
"aarch64-uwp-windows-gnu" => Some("aarch64-w64-mingw32"),
Expand Down Expand Up @@ -2994,7 +2985,7 @@ impl Build {
]), // explicit None if not found, so caller knows to fall back
"x86_64-unknown-linux-musl" => Some("musl"),
"x86_64-unknown-netbsd" => Some("x86_64--netbsd"),
_ => linker_prefix,
_ => None,
}
.map(|x| x.to_owned()))
}
Expand Down

0 comments on commit 9e50fb8

Please sign in to comment.