@@ -1106,7 +1106,7 @@ impl Build {
1106
1106
None => "none" ,
1107
1107
} ;
1108
1108
if cudart != "none" {
1109
- if let Some ( nvcc) = which ( & self . get_compiler ( ) . path ) {
1109
+ if let Some ( nvcc) = which ( & self . get_compiler ( ) . path , None ) {
1110
1110
// Try to figure out the -L search path. If it fails,
1111
1111
// it's on user to specify one by passing it through
1112
1112
// RUSTFLAGS environment variable.
@@ -2664,6 +2664,21 @@ impl Build {
2664
2664
}
2665
2665
2666
2666
"emar" . to_string ( )
2667
+ } else if target. starts_with ( "wasm32" ) {
2668
+ // Formally speaking one should be able to use this approach,
2669
+ // parsing -print-search-dirs output, to cover all clang targets,
2670
+ // including Android SDKs and other cross-compilation scenarios...
2671
+ // And even extend it to gcc targets by seaching for "ar" instead
2672
+ // of "llvm-ar"...
2673
+ let compiler = self . get_base_compiler ( ) ?;
2674
+ if compiler. family == ToolFamily :: Clang {
2675
+ match search_programs ( & mut self . cmd ( & compiler. path ) , "llvm-ar" ) {
2676
+ Some ( ar) => ar. to_str ( ) . unwrap ( ) . to_owned ( ) ,
2677
+ None => default_ar,
2678
+ }
2679
+ } else {
2680
+ default_ar
2681
+ }
2667
2682
} else if target. contains ( "msvc" ) {
2668
2683
let compiler = self . get_base_compiler ( ) ?;
2669
2684
let mut lib = String :: new ( ) ;
@@ -2673,10 +2688,10 @@ impl Build {
2673
2688
// next to 'clang-cl' and use 'search_programs()' to locate
2674
2689
// 'llvm-lib'. This is because 'clang-cl' doesn't support
2675
2690
// the -print-search-dirs option.
2676
- if let Some ( mut cmd) = which ( & compiler. path ) {
2691
+ if let Some ( mut cmd) = which ( & compiler. path , None ) {
2677
2692
cmd. pop ( ) ;
2678
2693
cmd. push ( "llvm-lib.exe" ) ;
2679
- if let Some ( llvm_lib) = which ( & cmd) {
2694
+ if let Some ( llvm_lib) = which ( & cmd, None ) {
2680
2695
lib = llvm_lib. to_str ( ) . unwrap ( ) . to_owned ( ) ;
2681
2696
}
2682
2697
}
@@ -3522,7 +3537,7 @@ fn map_darwin_target_from_rust_to_compiler_architecture(target: &str) -> Option<
3522
3537
}
3523
3538
}
3524
3539
3525
- fn which ( tool : & Path ) -> Option < PathBuf > {
3540
+ fn which ( tool : & Path , path_entries : Option < OsString > ) -> Option < PathBuf > {
3526
3541
fn check_exe ( exe : & mut PathBuf ) -> bool {
3527
3542
let exe_ext = std:: env:: consts:: EXE_EXTENSION ;
3528
3543
exe. exists ( ) || ( !exe_ext. is_empty ( ) && exe. set_extension ( exe_ext) && exe. exists ( ) )
@@ -3535,13 +3550,27 @@ fn which(tool: &Path) -> Option<PathBuf> {
3535
3550
}
3536
3551
3537
3552
// Loop through PATH entries searching for the |tool|.
3538
- let path_entries = env:: var_os ( "PATH" ) ?;
3553
+ let path_entries = path_entries . or ( env:: var_os ( "PATH" ) ) ?;
3539
3554
env:: split_paths ( & path_entries) . find_map ( |path_entry| {
3540
3555
let mut exe = path_entry. join ( tool) ;
3541
3556
return if check_exe ( & mut exe) { Some ( exe) } else { None } ;
3542
3557
} )
3543
3558
}
3544
3559
3560
+ // search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
3561
+ fn search_programs ( cc : & mut Command , prog : & str ) -> Option < PathBuf > {
3562
+ let search_dirs = run_output ( cc. arg ( "-print-search-dirs" ) , "cc" ) . ok ( ) ?;
3563
+ // clang driver appears to be forcing UTF-8 output even on Windows,
3564
+ // hence from_utf8 is assumed to be usable in all cases.
3565
+ let search_dirs = std:: str:: from_utf8 ( & search_dirs) . ok ( ) ?;
3566
+ for dirs in search_dirs. split ( |c| c == '\r' || c == '\n' ) {
3567
+ if dirs. starts_with ( "programs: =" ) {
3568
+ return which ( Path :: new ( prog) , Some ( OsString :: from ( & dirs[ 11 ..] ) ) ) ;
3569
+ }
3570
+ }
3571
+ None
3572
+ }
3573
+
3545
3574
#[ derive( Clone , Copy , PartialEq ) ]
3546
3575
enum AsmFileExt {
3547
3576
/// `.asm` files. On MSVC targets, we assume these should be passed to MASM
0 commit comments