@@ -11,7 +11,7 @@ use rustc_data_structures::sync;
11
11
use rustc_metadata:: { DylibError , load_symbol_from_dylib} ;
12
12
use rustc_middle:: ty:: CurrentGcx ;
13
13
use 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} ;
15
15
use rustc_session:: lint:: { self , BuiltinLintDiag , LintBuffer } ;
16
16
use rustc_session:: output:: { CRATE_TYPES , categorize_crate_type} ;
17
17
use rustc_session:: { EarlyDiagCtxt , Session , filesearch} ;
@@ -305,7 +305,7 @@ fn load_backend_from_dylib(early_dcx: &EarlyDiagCtxt, path: &Path) -> MakeBacken
305
305
/// A name of `None` indicates that the default backend should be used.
306
306
pub fn get_codegen_backend (
307
307
early_dcx : & EarlyDiagCtxt ,
308
- sysroot : & Path ,
308
+ sysroot : & Sysroot ,
309
309
backend_name : Option < & str > ,
310
310
target : & Target ,
311
311
) -> Box < dyn CodegenBackend > {
@@ -336,25 +336,24 @@ pub fn get_codegen_backend(
336
336
// This is used for rustdoc, but it uses similar machinery to codegen backend
337
337
// loading, so we leave the code here. It is potentially useful for other tools
338
338
// 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 > {
340
340
static RUSTC_PATH : OnceLock < Option < PathBuf > > = OnceLock :: new ( ) ;
341
341
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 ( )
352
351
}
353
352
354
353
#[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
355
354
fn get_codegen_sysroot (
356
355
early_dcx : & EarlyDiagCtxt ,
357
- sysroot : & Path ,
356
+ sysroot : & Sysroot ,
358
357
backend_name : & str ,
359
358
) -> MakeBackendFn {
360
359
// For now we only allow this function to be called once as it'll dlopen a
@@ -369,10 +368,9 @@ fn get_codegen_sysroot(
369
368
) ;
370
369
371
370
let target = host_tuple ( ) ;
372
- let sysroot_candidates = filesearch:: sysroot_with_fallback ( & sysroot) ;
373
371
374
- let sysroot = sysroot_candidates
375
- . iter ( )
372
+ let sysroot = sysroot
373
+ . all_paths ( )
376
374
. map ( |sysroot| {
377
375
filesearch:: make_target_lib_path ( sysroot, target) . with_file_name ( "codegen-backends" )
378
376
} )
@@ -381,8 +379,8 @@ fn get_codegen_sysroot(
381
379
f. exists ( )
382
380
} )
383
381
. unwrap_or_else ( || {
384
- let candidates = sysroot_candidates
385
- . iter ( )
382
+ let candidates = sysroot
383
+ . all_paths ( )
386
384
. map ( |p| p. display ( ) . to_string ( ) )
387
385
. collect :: < Vec < _ > > ( )
388
386
. join ( "\n * " ) ;
0 commit comments