@@ -11,7 +11,7 @@ use rustc_data_structures::sync;
1111use rustc_metadata:: { DylibError , load_symbol_from_dylib} ;
1212use rustc_middle:: ty:: CurrentGcx ;
1313use rustc_parse:: validate_attr;
14- use rustc_session:: config:: { Cfg , OutFileName , OutputFilenames , OutputTypes , host_tuple} ;
14+ use rustc_session:: config:: { Cfg , OutFileName , OutputFilenames , OutputTypes , Sysroot , host_tuple} ;
1515use rustc_session:: lint:: { self , BuiltinLintDiag , LintBuffer } ;
1616use rustc_session:: output:: { CRATE_TYPES , categorize_crate_type} ;
1717use rustc_session:: { EarlyDiagCtxt , Session , filesearch} ;
@@ -305,7 +305,7 @@ fn load_backend_from_dylib(early_dcx: &EarlyDiagCtxt, path: &Path) -> MakeBacken
305305/// A name of `None` indicates that the default backend should be used.
306306pub fn get_codegen_backend (
307307 early_dcx : & EarlyDiagCtxt ,
308- sysroot : & Path ,
308+ sysroot : & Sysroot ,
309309 backend_name : Option < & str > ,
310310 target : & Target ,
311311) -> Box < dyn CodegenBackend > {
@@ -336,25 +336,24 @@ pub fn get_codegen_backend(
336336// This is used for rustdoc, but it uses similar machinery to codegen backend
337337// loading, so we leave the code here. It is potentially useful for other tools
338338// that want to invoke the rustc binary while linking to rustc as well.
339- pub fn rustc_path < ' a > ( ) -> Option < & ' a Path > {
339+ pub fn rustc_path < ' a > ( sysroot : & Sysroot ) -> Option < & ' a Path > {
340340 static RUSTC_PATH : OnceLock < Option < PathBuf > > = OnceLock :: new ( ) ;
341341
342- const BIN_PATH : & str = env ! ( "RUSTC_INSTALL_BINDIR" ) ;
343-
344- RUSTC_PATH . get_or_init ( || get_rustc_path_inner ( BIN_PATH ) ) . as_deref ( )
345- }
346-
347- fn get_rustc_path_inner ( bin_path : & str ) -> Option < PathBuf > {
348- let candidate = filesearch:: get_or_default_sysroot ( )
349- . join ( bin_path)
350- . join ( if cfg ! ( target_os = "windows" ) { "rustc.exe" } else { "rustc" } ) ;
351- candidate. exists ( ) . then_some ( candidate)
342+ RUSTC_PATH
343+ . get_or_init ( || {
344+ let candidate = sysroot
345+ . default
346+ . join ( env ! ( "RUSTC_INSTALL_BINDIR" ) )
347+ . join ( if cfg ! ( target_os = "windows" ) { "rustc.exe" } else { "rustc" } ) ;
348+ candidate. exists ( ) . then_some ( candidate)
349+ } )
350+ . as_deref ( )
352351}
353352
354353#[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
355354fn get_codegen_sysroot (
356355 early_dcx : & EarlyDiagCtxt ,
357- sysroot : & Path ,
356+ sysroot : & Sysroot ,
358357 backend_name : & str ,
359358) -> MakeBackendFn {
360359 // For now we only allow this function to be called once as it'll dlopen a
@@ -369,10 +368,9 @@ fn get_codegen_sysroot(
369368 ) ;
370369
371370 let target = host_tuple ( ) ;
372- let sysroot_candidates = filesearch:: sysroot_with_fallback ( & sysroot) ;
373371
374- let sysroot = sysroot_candidates
375- . iter ( )
372+ let sysroot = sysroot
373+ . all_paths ( )
376374 . map ( |sysroot| {
377375 filesearch:: make_target_lib_path ( sysroot, target) . with_file_name ( "codegen-backends" )
378376 } )
@@ -381,8 +379,8 @@ fn get_codegen_sysroot(
381379 f. exists ( )
382380 } )
383381 . unwrap_or_else ( || {
384- let candidates = sysroot_candidates
385- . iter ( )
382+ let candidates = sysroot
383+ . all_paths ( )
386384 . map ( |p| p. display ( ) . to_string ( ) )
387385 . collect :: < Vec < _ > > ( )
388386 . join ( "\n * " ) ;
0 commit comments