mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
infer linker flavor by linker name if it's sufficiently specific
This commit is contained in:
parent
eeb9035117
commit
c23bf48e4f
@ -303,15 +303,16 @@ impl LinkerFlavor {
|
||||
}
|
||||
}
|
||||
|
||||
fn infer_linker_hints(linker_stem: &str) -> (Option<Cc>, Option<Lld>) {
|
||||
fn infer_linker_hints(linker_stem: &str) -> Result<Self, (Option<Cc>, Option<Lld>)> {
|
||||
// Remove any version postfix.
|
||||
let stem = linker_stem
|
||||
.rsplit_once('-')
|
||||
.and_then(|(lhs, rhs)| rhs.chars().all(char::is_numeric).then_some(lhs))
|
||||
.unwrap_or(linker_stem);
|
||||
|
||||
// GCC/Clang can have an optional target prefix.
|
||||
if stem == "emcc"
|
||||
if stem == "llvm-bitcode-linker" {
|
||||
Ok(Self::Llbc)
|
||||
} else if stem == "emcc" // GCC/Clang can have an optional target prefix.
|
||||
|| stem == "gcc"
|
||||
|| stem.ends_with("-gcc")
|
||||
|| stem == "g++"
|
||||
@ -321,7 +322,7 @@ impl LinkerFlavor {
|
||||
|| stem == "clang++"
|
||||
|| stem.ends_with("-clang++")
|
||||
{
|
||||
(Some(Cc::Yes), Some(Lld::No))
|
||||
Err((Some(Cc::Yes), Some(Lld::No)))
|
||||
} else if stem == "wasm-ld"
|
||||
|| stem.ends_with("-wasm-ld")
|
||||
|| stem == "ld.lld"
|
||||
@ -329,11 +330,11 @@ impl LinkerFlavor {
|
||||
|| stem == "rust-lld"
|
||||
|| stem == "lld-link"
|
||||
{
|
||||
(Some(Cc::No), Some(Lld::Yes))
|
||||
Err((Some(Cc::No), Some(Lld::Yes)))
|
||||
} else if stem == "ld" || stem.ends_with("-ld") || stem == "link" {
|
||||
(Some(Cc::No), Some(Lld::No))
|
||||
Err((Some(Cc::No), Some(Lld::No)))
|
||||
} else {
|
||||
(None, None)
|
||||
Err((None, None))
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,7 +358,10 @@ impl LinkerFlavor {
|
||||
}
|
||||
|
||||
pub fn with_linker_hints(self, linker_stem: &str) -> LinkerFlavor {
|
||||
self.with_hints(LinkerFlavor::infer_linker_hints(linker_stem))
|
||||
match LinkerFlavor::infer_linker_hints(linker_stem) {
|
||||
Ok(linker_flavor) => linker_flavor,
|
||||
Err(hints) => self.with_hints(hints),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_compatibility(self, cli: LinkerFlavorCli) -> Option<String> {
|
||||
|
Loading…
Reference in New Issue
Block a user