@@ -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.
@@ -2534,7 +2534,15 @@ impl Build {
2534
2534
None => default_ar,
2535
2535
}
2536
2536
} else {
2537
- default_ar
2537
+ let compiler = self . get_base_compiler ( ) ?;
2538
+ if compiler. family == ToolFamily :: Clang {
2539
+ match search_programs ( & mut self . cmd ( & compiler. path ) , "llvm-ar" ) {
2540
+ Some ( ar) => ar. to_str ( ) . unwrap ( ) . to_owned ( ) ,
2541
+ None => default_ar,
2542
+ }
2543
+ } else {
2544
+ default_ar
2545
+ }
2538
2546
} ;
2539
2547
Ok ( ( self . cmd ( & program) , program) )
2540
2548
}
@@ -3280,7 +3288,7 @@ fn map_darwin_target_from_rust_to_compiler_architecture(target: &str) -> Option<
3280
3288
}
3281
3289
}
3282
3290
3283
- fn which ( tool : & Path ) -> Option < PathBuf > {
3291
+ fn which ( tool : & Path , path_entries : Option < OsString > ) -> Option < PathBuf > {
3284
3292
fn check_exe ( exe : & mut PathBuf ) -> bool {
3285
3293
let exe_ext = std:: env:: consts:: EXE_EXTENSION ;
3286
3294
exe. exists ( ) || ( !exe_ext. is_empty ( ) && exe. set_extension ( exe_ext) && exe. exists ( ) )
@@ -3293,9 +3301,23 @@ fn which(tool: &Path) -> Option<PathBuf> {
3293
3301
}
3294
3302
3295
3303
// Loop through PATH entries searching for the |tool|.
3296
- let path_entries = env:: var_os ( "PATH" ) ?;
3304
+ let path_entries = path_entries . or ( env:: var_os ( "PATH" ) ) ?;
3297
3305
env:: split_paths ( & path_entries) . find_map ( |path_entry| {
3298
3306
let mut exe = path_entry. join ( tool) ;
3299
3307
return if check_exe ( & mut exe) { Some ( exe) } else { None } ;
3300
3308
} )
3301
3309
}
3310
+
3311
+ // search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
3312
+ fn search_programs ( cc : & mut Command , prog : & str ) -> Option < PathBuf > {
3313
+ let search_dirs = run_output ( cc. arg ( "-print-search-dirs" ) , "cc" ) . ok ( ) ?;
3314
+ // clang driver appears to be forcing UTF-8 output even on Windows,
3315
+ // hence from_utf8 is assumed to be usable in all cases.
3316
+ let search_dirs = std:: str:: from_utf8 ( & search_dirs) . ok ( ) ?;
3317
+ for dirs in search_dirs. split ( |c| c == '\r' || c == '\n' ) {
3318
+ if dirs. starts_with ( "programs: =" ) {
3319
+ return which ( Path :: new ( prog) , Some ( OsString :: from ( & dirs[ 11 ..] ) ) ) ;
3320
+ }
3321
+ }
3322
+ None
3323
+ }
0 commit comments