diff options
| author | Rémy Rakic <remy.rakic+github@gmail.com> | 2022-09-06 15:54:20 +0200 |
|---|---|---|
| committer | Rémy Rakic <remy.rakic+github@gmail.com> | 2022-09-07 14:51:54 +0200 |
| commit | 5f25154813b6eeb353bd7f0f758c4475cd239ffd (patch) | |
| tree | 1eafb0b7d33427c52b144a2d4f6c880b4da6480d | |
| parent | a594044533b5e309eab7ac6b71f4ba8a909af653 (diff) | |
| download | rust-5f25154813b6eeb353bd7f0f758c4475cd239ffd.tar.gz rust-5f25154813b6eeb353bd7f0f758c4475cd239ffd.zip | |
fix lld-wrapper lld flavor detection
| -rw-r--r-- | src/tools/lld-wrapper/src/main.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/tools/lld-wrapper/src/main.rs b/src/tools/lld-wrapper/src/main.rs index 1795f3d7fe5..b5e977b2637 100644 --- a/src/tools/lld-wrapper/src/main.rs +++ b/src/tools/lld-wrapper/src/main.rs @@ -11,9 +11,10 @@ //! obtained from the wrapper's name as the first two arguments. //! On Windows it spawns a `..\rust-lld.exe` child process. +use std::env::{self, consts::EXE_SUFFIX}; use std::fmt::Display; use std::path::{Path, PathBuf}; -use std::{env, process}; +use std::process; trait UnwrapOrExitWith<T> { fn unwrap_or_exit_with(self, context: &str) -> T; @@ -42,7 +43,7 @@ impl<T, E: Display> UnwrapOrExitWith<T> for Result<T, E> { /// Exits if the parent directory cannot be determined. fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf { let mut rust_lld_exe_name = "rust-lld".to_owned(); - rust_lld_exe_name.push_str(env::consts::EXE_SUFFIX); + rust_lld_exe_name.push_str(EXE_SUFFIX); let mut rust_lld_path = current_exe_path .parent() .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 { /// Extract LLD flavor name from the lld-wrapper executable name. fn get_lld_flavor(current_exe_path: &Path) -> Result<&'static str, String> { - let stem = current_exe_path.file_stem(); - Ok(match stem.and_then(|s| s.to_str()) { + let file = current_exe_path.file_name(); + let stem = file.and_then(|s| s.to_str()).map(|s| s.trim_end_matches(EXE_SUFFIX)); + Ok(match stem { Some("ld.lld") => "gnu", Some("ld64.lld") => "darwin", Some("lld-link") => "link", Some("wasm-ld") => "wasm", - _ => return Err(format!("{:?}", stem)), + _ => return Err(format!("{:?}", file)), }) } |
