Skip to content

Commit 9e50fb8

Browse files
authored
Prioritize RUSTC_LINKER over target->cross-compile-prefix table. (#767)
fix #654
1 parent 6008cbf commit 9e50fb8

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/lib.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -2864,23 +2864,14 @@ impl Build {
28642864
}
28652865

28662866
fn prefix_for_target(&self, target: &str) -> Option<String> {
2867-
// Put aside RUSTC_LINKER's prefix to be used as last resort
2868-
let rustc_linker = self.getenv("RUSTC_LINKER").unwrap_or("".to_string());
2869-
// let linker_prefix = rustc_linker.strip_suffix("-gcc"); // >=1.45.0
2870-
let linker_prefix = if rustc_linker.len() > 4 {
2871-
let (prefix, suffix) = rustc_linker.split_at(rustc_linker.len() - 4);
2872-
if suffix == "-gcc" {
2873-
Some(prefix)
2874-
} else {
2875-
None
2876-
}
2877-
} else {
2878-
None
2879-
};
2867+
// Put aside RUSTC_LINKER's prefix to be used as second choice, after CROSS_COMPILE
2868+
let linker_prefix = self
2869+
.getenv("RUSTC_LINKER")
2870+
.and_then(|var| var.strip_suffix("-gcc").map(str::to_string));
28802871
// CROSS_COMPILE is of the form: "arm-linux-gnueabi-"
28812872
let cc_env = self.getenv("CROSS_COMPILE");
28822873
let cross_compile = cc_env.as_ref().map(|s| s.trim_end_matches('-').to_owned());
2883-
cross_compile.or(match &target[..] {
2874+
cross_compile.or(linker_prefix).or(match &target[..] {
28842875
// Note: there is no `aarch64-pc-windows-gnu` target, only `-gnullvm`
28852876
"aarch64-pc-windows-gnullvm" => Some("aarch64-w64-mingw32"),
28862877
"aarch64-uwp-windows-gnu" => Some("aarch64-w64-mingw32"),
@@ -2994,7 +2985,7 @@ impl Build {
29942985
]), // explicit None if not found, so caller knows to fall back
29952986
"x86_64-unknown-linux-musl" => Some("musl"),
29962987
"x86_64-unknown-netbsd" => Some("x86_64--netbsd"),
2997-
_ => linker_prefix,
2988+
_ => None,
29982989
}
29992990
.map(|x| x.to_owned()))
30002991
}

0 commit comments

Comments
 (0)