Skip to content

Commit 48a0f0d

Browse files
committed
Prioritize RUSTC_LINKER over target->cross-compile-prefix table.
Rationale is that if rustc is explicitly instructed to use a specific linker, using it as base for cross-compile prefix would be better aligned with user expectations.
1 parent 203a57f commit 48a0f0d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,13 +2721,13 @@ impl Build {
27212721
}
27222722

27232723
fn prefix_for_target(&self, target: &str) -> Option<String> {
2724-
// Put aside RUSTC_LINKER's prefix to be used as last resort
2724+
// Put aside RUSTC_LINKER's prefix to be used as second choice, after CROSS_COMPILE
27252725
let rustc_linker = self.getenv("RUSTC_LINKER").unwrap_or("".to_string());
27262726
// let linker_prefix = rustc_linker.strip_suffix("-gcc"); // >=1.45.0
27272727
let linker_prefix = if rustc_linker.len() > 4 {
27282728
let (prefix, suffix) = rustc_linker.split_at(rustc_linker.len() - 4);
27292729
if suffix == "-gcc" {
2730-
Some(prefix)
2730+
Some(prefix.to_string())
27312731
} else {
27322732
None
27332733
}
@@ -2737,7 +2737,7 @@ impl Build {
27372737
// CROSS_COMPILE is of the form: "arm-linux-gnueabi-"
27382738
let cc_env = self.getenv("CROSS_COMPILE");
27392739
let cross_compile = cc_env.as_ref().map(|s| s.trim_end_matches('-').to_owned());
2740-
cross_compile.or(match &target[..] {
2740+
cross_compile.or(linker_prefix).or(match &target[..] {
27412741
// Note: there is no `aarch64-pc-windows-gnu` target, only `-gnullvm`
27422742
"aarch64-pc-windows-gnullvm" => Some("aarch64-w64-mingw32"),
27432743
"aarch64-uwp-windows-gnu" => Some("aarch64-w64-mingw32"),
@@ -2850,7 +2850,7 @@ impl Build {
28502850
]), // explicit None if not found, so caller knows to fall back
28512851
"x86_64-unknown-linux-musl" => Some("musl"),
28522852
"x86_64-unknown-netbsd" => Some("x86_64--netbsd"),
2853-
_ => linker_prefix,
2853+
_ => None,
28542854
}
28552855
.map(|x| x.to_owned()))
28562856
}

0 commit comments

Comments
 (0)