diff options
Diffstat (limited to 'compiler/rustc_interface/src/util.rs')
| -rw-r--r-- | compiler/rustc_interface/src/util.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 8a7d6117265..0ca4fcc66ca 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -11,7 +11,7 @@ use rustc_data_structures::sync; use rustc_metadata::{DylibError, load_symbol_from_dylib}; use rustc_middle::ty::CurrentGcx; use rustc_parse::validate_attr; -use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, host_tuple}; +use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple}; use rustc_session::lint::{self, BuiltinLintDiag, LintBuffer}; use rustc_session::output::{CRATE_TYPES, categorize_crate_type}; use rustc_session::{EarlyDiagCtxt, Session, filesearch}; @@ -305,7 +305,7 @@ fn load_backend_from_dylib(early_dcx: &EarlyDiagCtxt, path: &Path) -> MakeBacken /// A name of `None` indicates that the default backend should be used. pub fn get_codegen_backend( early_dcx: &EarlyDiagCtxt, - sysroot: &Path, + sysroot: &Sysroot, backend_name: Option<&str>, target: &Target, ) -> Box<dyn CodegenBackend> { @@ -336,25 +336,24 @@ pub fn get_codegen_backend( // This is used for rustdoc, but it uses similar machinery to codegen backend // loading, so we leave the code here. It is potentially useful for other tools // that want to invoke the rustc binary while linking to rustc as well. -pub fn rustc_path<'a>() -> Option<&'a Path> { +pub fn rustc_path<'a>(sysroot: &Sysroot) -> Option<&'a Path> { static RUSTC_PATH: OnceLock<Option<PathBuf>> = OnceLock::new(); - const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR"); - - RUSTC_PATH.get_or_init(|| get_rustc_path_inner(BIN_PATH)).as_deref() -} - -fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> { - let candidate = filesearch::get_or_default_sysroot() - .join(bin_path) - .join(if cfg!(target_os = "windows") { "rustc.exe" } else { "rustc" }); - candidate.exists().then_some(candidate) + RUSTC_PATH + .get_or_init(|| { + let candidate = sysroot + .default + .join(env!("RUSTC_INSTALL_BINDIR")) + .join(if cfg!(target_os = "windows") { "rustc.exe" } else { "rustc" }); + candidate.exists().then_some(candidate) + }) + .as_deref() } #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable fn get_codegen_sysroot( early_dcx: &EarlyDiagCtxt, - sysroot: &Path, + sysroot: &Sysroot, backend_name: &str, ) -> MakeBackendFn { // For now we only allow this function to be called once as it'll dlopen a @@ -369,10 +368,9 @@ fn get_codegen_sysroot( ); let target = host_tuple(); - let sysroot_candidates = filesearch::sysroot_with_fallback(&sysroot); - let sysroot = sysroot_candidates - .iter() + let sysroot = sysroot + .all_paths() .map(|sysroot| { filesearch::make_target_lib_path(sysroot, target).with_file_name("codegen-backends") }) @@ -381,8 +379,8 @@ fn get_codegen_sysroot( f.exists() }) .unwrap_or_else(|| { - let candidates = sysroot_candidates - .iter() + let candidates = sysroot + .all_paths() .map(|p| p.display().to_string()) .collect::<Vec<_>>() .join("\n* "); |
