@@ -449,15 +449,24 @@ impl Session {
449449 )
450450 }
451451
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.
453455 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+ }
461470 }
462471
463472 pub fn init_incr_comp_session ( & self , session_dir : PathBuf , lock_file : flock:: Lock ) {
0 commit comments