Skip to content

Commit 5f25154

Browse files
committed
fix lld-wrapper lld flavor detection
1 parent a594044 commit 5f25154

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/tools/lld-wrapper/src/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
//! obtained from the wrapper's name as the first two arguments.
1212
//! On Windows it spawns a `..\rust-lld.exe` child process.
1313
14+
use std::env::{self, consts::EXE_SUFFIX};
1415
use std::fmt::Display;
1516
use std::path::{Path, PathBuf};
16-
use std::{env, process};
17+
use std::process;
1718

1819
trait UnwrapOrExitWith<T> {
1920
fn unwrap_or_exit_with(self, context: &str) -> T;
@@ -42,7 +43,7 @@ impl<T, E: Display> UnwrapOrExitWith<T> for Result<T, E> {
4243
/// Exits if the parent directory cannot be determined.
4344
fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf {
4445
let mut rust_lld_exe_name = "rust-lld".to_owned();
45-
rust_lld_exe_name.push_str(env::consts::EXE_SUFFIX);
46+
rust_lld_exe_name.push_str(EXE_SUFFIX);
4647
let mut rust_lld_path = current_exe_path
4748
.parent()
4849
.unwrap_or_exit_with("directory containing current executable could not be determined")
@@ -55,13 +56,14 @@ fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf {
5556

5657
/// Extract LLD flavor name from the lld-wrapper executable name.
5758
fn get_lld_flavor(current_exe_path: &Path) -> Result<&'static str, String> {
58-
let stem = current_exe_path.file_stem();
59-
Ok(match stem.and_then(|s| s.to_str()) {
59+
let file = current_exe_path.file_name();
60+
let stem = file.and_then(|s| s.to_str()).map(|s| s.trim_end_matches(EXE_SUFFIX));
61+
Ok(match stem {
6062
Some("ld.lld") => "gnu",
6163
Some("ld64.lld") => "darwin",
6264
Some("lld-link") => "link",
6365
Some("wasm-ld") => "wasm",
64-
_ => return Err(format!("{:?}", stem)),
66+
_ => return Err(format!("{:?}", file)),
6567
})
6668
}
6769

0 commit comments

Comments
 (0)