Skip to content

Commit bac5344

Browse files
committed
centralize fallback sysroot search paths in get_tools_search_paths
1 parent d8284a3 commit bac5344

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -3117,16 +3117,12 @@ fn add_lld_args(
31173117
let self_contained_linker = self_contained_cli || self_contained_target;
31183118
if self_contained_linker && !sess.opts.cg.link_self_contained.is_linker_disabled() {
31193119
// We tell `cc` where to find the lld wrappers, in a similar way to how we locate
3120-
// codegen-backends dylibs:
3121-
// - in the tool search paths: the sysroot's `rustlib` bin path,
3122-
// - and as a fallback for cases where `--sysroot` only contains a target std: in the
3123-
// default host sysroot where rustc is currently located.
3124-
let fallback_sysroot_paths = filesearch::sysroot_candidates()
3125-
.into_iter()
3126-
.map(|sysroot| filesearch::make_target_bin_path(&sysroot, config::host_triple()));
3127-
3120+
// codegen-backends dylibs, in the tools search paths, which contain:
3121+
// - the sysroot's `rustlib` bin path,
3122+
// - and as a fallback for cases using `--sysroot` without tools: in the default host
3123+
// sysroot where rustc is currently located.
31283124
let mut linker_path_exists = false;
3129-
for path in sess.get_tools_search_paths(false).into_iter().chain(fallback_sysroot_paths) {
3125+
for path in sess.get_tools_search_paths(false) {
31303126
let linker_path = path.join("gcc-ld");
31313127
if linker_path.exists() {
31323128
linker_path_exists = true;

compiler/rustc_session/src/session.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,29 @@ 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> {
454456
let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, config::host_triple());
455457
let p = PathBuf::from_iter([
456458
Path::new(&self.sysroot),
457459
Path::new(&rustlib_path),
458460
Path::new("bin"),
459461
]);
460-
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
462+
463+
let fallback_sysroot_paths = filesearch::sysroot_candidates()
464+
.into_iter()
465+
.map(|sysroot| filesearch::make_target_bin_path(&sysroot, config::host_triple()));
466+
467+
if self_contained {
468+
[p.clone(), p.join("self-contained")]
469+
.into_iter()
470+
.chain(fallback_sysroot_paths)
471+
.collect()
472+
} else {
473+
std::iter::once(p).chain(fallback_sysroot_paths).collect()
474+
}
461475
}
462476

463477
pub fn init_incr_comp_session(&self, session_dir: PathBuf, lock_file: flock::Lock) {

0 commit comments

Comments
 (0)