diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-06-05 16:53:12 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-06-05 16:54:10 +0000 |
| commit | dff8ee5b01b7251937860da41afd55958c13456a (patch) | |
| tree | 282ebea0dfc1d9000d1cbbab71a6b1d8359978de /compiler/rustc_interface/src/util.rs | |
| parent | 387dae9092414888e9291efd9317068458250a49 (diff) | |
| download | rust-dff8ee5b01b7251937860da41afd55958c13456a.tar.gz rust-dff8ee5b01b7251937860da41afd55958c13456a.zip | |
Replace all uses of sysroot_candidates with get_or_default_sysroot
Before this change we had two different ways to attempt to locate the sysroot which are inconsistently used: * get_or_default_sysroot which tries to locate based on the 0th cli argument and if that doesn't work falls back to locating it using the librustc_driver.so location and returns a single path., * sysroot_candidates which takes the former and additionally does another attempt at locating using librustc_driver.so except without linux multiarch handling and then returns both paths., The latter was originally introduced to be able to locate the codegen backend back when cg_llvm was dynamically linked even for a custom driver when the --sysroot passed in does not contain a copy of cg_llvm. Back then get_or_default_sysroot did not attempt to locate the sysroot based on the location of librustc_driver.so yet. Because that is now done, the only case where removing sysroot_candidates can break things is if you have a custom driver inside what looks like a sysroot including the lib/rustlib directory, but which is missing some parts of the full sysroot like eg rust-lld.
Diffstat (limited to 'compiler/rustc_interface/src/util.rs')
| -rw-r--r-- | compiler/rustc_interface/src/util.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 087b11fdf9d..f769c6156ae 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -2,7 +2,7 @@ use std::env::consts::{DLL_PREFIX, DLL_SUFFIX}; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, OnceLock}; -use std::{env, iter, thread}; +use std::{env, thread}; use rustc_ast as ast; use rustc_codegen_ssa::traits::CodegenBackend; @@ -12,7 +12,6 @@ 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::filesearch::sysroot_candidates; use rustc_session::lint::{self, BuiltinLintDiag, LintBuffer}; use rustc_session::output::{CRATE_TYPES, categorize_crate_type}; use rustc_session::{EarlyDiagCtxt, Session, filesearch}; @@ -346,7 +345,7 @@ pub fn rustc_path<'a>() -> Option<&'a Path> { } fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> { - sysroot_candidates().iter().find_map(|sysroot| { + Some(filesearch::get_or_default_sysroot()).iter().find_map(|sysroot| { let candidate = sysroot.join(bin_path).join(if cfg!(target_os = "windows") { "rustc.exe" } else { @@ -374,10 +373,10 @@ fn get_codegen_sysroot( ); let target = host_tuple(); - let sysroot_candidates = sysroot_candidates(); + let sysroot_candidates = filesearch::sysroot_with_fallback(&sysroot); - let sysroot = iter::once(sysroot) - .chain(sysroot_candidates.iter().map(<_>::as_ref)) + let sysroot = sysroot_candidates + .iter() .map(|sysroot| { filesearch::make_target_lib_path(sysroot, target).with_file_name("codegen-backends") }) |
