@@ -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.
@@ -2565,6 +2565,21 @@ impl Build {
2565
2565
}
2566
2566
2567
2567
"emar" . to_string ( )
2568
+ } else if target. starts_with ( "wasm32" ) {
2569
+ // Formally speaking one should be able to use this approach,
2570
+ // parsing -print-search-dirs output, to cover all clang targets,
2571
+ // including Android SDKs and other cross-compilation scenarios...
2572
+ // And even extend it to gcc targets by seaching for "ar" instead
2573
+ // of "llvm-ar"...
2574
+ let compiler = self . get_base_compiler ( ) ?;
2575
+ if compiler. family == ToolFamily :: Clang {
2576
+ match search_programs ( & mut self . cmd ( & compiler. path ) , "llvm-ar" ) {
2577
+ Some ( ar) => ar. to_str ( ) . unwrap ( ) . to_owned ( ) ,
2578
+ None => default_ar,
2579
+ }
2580
+ } else {
2581
+ default_ar
2582
+ }
2568
2583
} else if target. contains ( "msvc" ) {
2569
2584
match windows_registry:: find ( & target, "lib.exe" ) {
2570
2585
Some ( t) => return Ok ( ( t, "lib.exe" . to_string ( ) ) ) ,
@@ -3335,7 +3350,7 @@ fn map_darwin_target_from_rust_to_compiler_architecture(target: &str) -> Option<
3335
3350
}
3336
3351
}
3337
3352
3338
- fn which ( tool : & Path ) -> Option < PathBuf > {
3353
+ fn which ( tool : & Path , path_entries : Option < OsString > ) -> Option < PathBuf > {
3339
3354
fn check_exe ( exe : & mut PathBuf ) -> bool {
3340
3355
let exe_ext = std:: env:: consts:: EXE_EXTENSION ;
3341
3356
exe. exists ( ) || ( !exe_ext. is_empty ( ) && exe. set_extension ( exe_ext) && exe. exists ( ) )
@@ -3348,9 +3363,23 @@ fn which(tool: &Path) -> Option<PathBuf> {
3348
3363
}
3349
3364
3350
3365
// Loop through PATH entries searching for the |tool|.
3351
- let path_entries = env:: var_os ( "PATH" ) ?;
3366
+ let path_entries = path_entries . or ( env:: var_os ( "PATH" ) ) ?;
3352
3367
env:: split_paths ( & path_entries) . find_map ( |path_entry| {
3353
3368
let mut exe = path_entry. join ( tool) ;
3354
3369
return if check_exe ( & mut exe) { Some ( exe) } else { None } ;
3355
3370
} )
3356
3371
}
3372
+
3373
+ // search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
3374
+ fn search_programs ( cc : & mut Command , prog : & str ) -> Option < PathBuf > {
3375
+ let search_dirs = run_output ( cc. arg ( "-print-search-dirs" ) , "cc" ) . ok ( ) ?;
3376
+ // clang driver appears to be forcing UTF-8 output even on Windows,
3377
+ // hence from_utf8 is assumed to be usable in all cases.
3378
+ let search_dirs = std:: str:: from_utf8 ( & search_dirs) . ok ( ) ?;
3379
+ for dirs in search_dirs. split ( |c| c == '\r' || c == '\n' ) {
3380
+ if dirs. starts_with ( "programs: =" ) {
3381
+ return which ( Path :: new ( prog) , Some ( OsString :: from ( & dirs[ 11 ..] ) ) ) ;
3382
+ }
3383
+ }
3384
+ None
3385
+ }
0 commit comments