@@ -449,15 +449,24 @@ impl Session {
449
449
)
450
450
}
451
451
452
- /// Returns a list of directories where target-specific tool binaries are located.
452
+ /// Returns a list of directories where target-specific tool binaries are located. Some fallback
453
+ /// directories are also returned, for example if `--sysroot` is used but tools are missing
454
+ /// (#125246): we also add the bin directories to the sysroot where rustc is located.
453
455
pub fn get_tools_search_paths ( & self , self_contained : bool ) -> Vec < PathBuf > {
454
- let rustlib_path = rustc_target:: target_rustlib_path ( & self . sysroot , config:: host_triple ( ) ) ;
455
- let p = PathBuf :: from_iter ( [
456
- Path :: new ( & self . sysroot ) ,
457
- Path :: new ( & rustlib_path) ,
458
- Path :: new ( "bin" ) ,
459
- ] ) ;
460
- if self_contained { vec ! [ p. clone( ) , p. join( "self-contained" ) ] } else { vec ! [ p] }
456
+ let bin_path = filesearch:: make_target_bin_path ( & self . sysroot , config:: host_triple ( ) ) ;
457
+ let fallback_sysroot_paths = filesearch:: sysroot_candidates ( )
458
+ . into_iter ( )
459
+ . map ( |sysroot| filesearch:: make_target_bin_path ( & sysroot, config:: host_triple ( ) ) ) ;
460
+ let search_paths = std:: iter:: once ( bin_path) . chain ( fallback_sysroot_paths) ;
461
+
462
+ if self_contained {
463
+ // The self-contained tools are expected to be e.g. in `bin/self-contained` in the
464
+ // sysroot's `rustlib` path, so we add such a subfolder to the bin path, and the
465
+ // fallback paths.
466
+ search_paths. flat_map ( |path| [ path. clone ( ) , path. join ( "self-contained" ) ] ) . collect ( )
467
+ } else {
468
+ search_paths. collect ( )
469
+ }
461
470
}
462
471
463
472
pub fn init_incr_comp_session ( & self , session_dir : PathBuf , lock_file : flock:: Lock ) {
0 commit comments