@@ -1029,7 +1029,7 @@ impl Build {
1029
1029
None => "none" ,
1030
1030
} ;
1031
1031
if cudart != "none" {
1032
- if let Some ( nvcc) = which ( & self . get_compiler ( ) . path ) {
1032
+ if let Some ( nvcc) = which ( & self . get_compiler ( ) . path , None ) {
1033
1033
// Try to figure out the -L search path. If it fails,
1034
1034
// it's on user to specify one by passing it through
1035
1035
// RUSTFLAGS environment variable.
@@ -2540,6 +2540,21 @@ impl Build {
2540
2540
}
2541
2541
None => default_ar,
2542
2542
}
2543
+ } else if target. starts_with ( "wasm32" ) {
2544
+ // Formally speaking one should be able to use this approach,
2545
+ // parsing -print-search-dirs output, to cover all clang targets,
2546
+ // including Android SDKs and other cross-compilation scenarios...
2547
+ // And even extend it to gcc targets by seaching for "ar" instead
2548
+ // of "llvm-ar"...
2549
+ let compiler = self . get_base_compiler ( ) ?;
2550
+ if compiler. family == ToolFamily :: Clang {
2551
+ match search_programs ( & mut self . cmd ( & compiler. path ) , "llvm-ar" ) {
2552
+ Some ( ar) => ar. to_str ( ) . unwrap ( ) . to_owned ( ) ,
2553
+ None => default_ar,
2554
+ }
2555
+ } else {
2556
+ default_ar
2557
+ }
2543
2558
} else {
2544
2559
default_ar
2545
2560
} ;
@@ -3287,7 +3302,7 @@ fn map_darwin_target_from_rust_to_compiler_architecture(target: &str) -> Option<
3287
3302
}
3288
3303
}
3289
3304
3290
- fn which ( tool : & Path ) -> Option < PathBuf > {
3305
+ fn which ( tool : & Path , path_entries : Option < OsString > ) -> Option < PathBuf > {
3291
3306
fn check_exe ( exe : & mut PathBuf ) -> bool {
3292
3307
let exe_ext = std:: env:: consts:: EXE_EXTENSION ;
3293
3308
exe. exists ( ) || ( !exe_ext. is_empty ( ) && exe. set_extension ( exe_ext) && exe. exists ( ) )
@@ -3300,9 +3315,23 @@ fn which(tool: &Path) -> Option<PathBuf> {
3300
3315
}
3301
3316
3302
3317
// Loop through PATH entries searching for the |tool|.
3303
- let path_entries = env:: var_os ( "PATH" ) ?;
3318
+ let path_entries = path_entries . or ( env:: var_os ( "PATH" ) ) ?;
3304
3319
env:: split_paths ( & path_entries) . find_map ( |path_entry| {
3305
3320
let mut exe = path_entry. join ( tool) ;
3306
3321
return if check_exe ( & mut exe) { Some ( exe) } else { None } ;
3307
3322
} )
3308
3323
}
3324
+
3325
+ // search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
3326
+ fn search_programs ( cc : & mut Command , prog : & str ) -> Option < PathBuf > {
3327
+ let search_dirs = run_output ( cc. arg ( "-print-search-dirs" ) , "cc" ) . ok ( ) ?;
3328
+ // clang driver appears to be forcing UTF-8 output even on Windows,
3329
+ // hence from_utf8 is assumed to be usable in all cases.
3330
+ let search_dirs = std:: str:: from_utf8 ( & search_dirs) . ok ( ) ?;
3331
+ for dirs in search_dirs. split ( |c| c == '\r' || c == '\n' ) {
3332
+ if dirs. starts_with ( "programs: =" ) {
3333
+ return which ( Path :: new ( prog) , Some ( OsString :: from ( & dirs[ 11 ..] ) ) ) ;
3334
+ }
3335
+ }
3336
+ None
3337
+ }
0 commit comments