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 } ;
1415use std:: fmt:: Display ;
1516use std:: path:: { Path , PathBuf } ;
16- use std:: { env , process} ;
17+ use std:: process;
1718
1819trait 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.
4344fn 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.
5758fn 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