Skip to content

Commit 5a7e065

Browse files
committed
resolve target-libdir directly from rustc
Leaving stage0 target-libdir resolution to rustc. This should also fix the issue with hard-coding `$sysroot/lib` which fails on systems that use `$sysroot/lib64` or `$sysroot/lib32`. Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 38081f2 commit 5a7e065

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/bootstrap/src/lib.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,19 +363,33 @@ impl Build {
363363
let in_tree_llvm_info = config.in_tree_llvm_info.clone();
364364
let in_tree_gcc_info = config.in_tree_gcc_info.clone();
365365

366-
let initial_target_libdir_str =
367-
config.initial_sysroot.join("lib/rustlib").join(config.build).join("lib");
366+
let initial_target_libdir =
367+
output(Command::new(&config.initial_rustc).args(["--print", "target-libdir"]));
368+
369+
let initial_target_dir = Path::new(&initial_target_libdir)
370+
.parent()
371+
.unwrap_or_else(|| panic!("{initial_target_libdir} has no parent"));
368372

369-
let initial_target_dir = Path::new(&initial_target_libdir_str).parent().unwrap();
370373
let initial_lld = initial_target_dir.join("bin").join("rust-lld");
371374

372-
let initial_relative_libdir = initial_target_dir
373-
.ancestors()
374-
.nth(2)
375-
.unwrap()
376-
.strip_prefix(&config.initial_sysroot)
377-
.expect("Couldn’t determine initial relative libdir.")
378-
.to_path_buf();
375+
let initial_relative_libdir = if cfg!(test) {
376+
// On tests, bootstrap uses the shim rustc, not the one from the stage0 toolchain.
377+
PathBuf::default()
378+
} else {
379+
let ancestor = initial_target_dir.ancestors().nth(2).unwrap_or_else(|| {
380+
panic!("Not enough ancestors for {}", initial_target_dir.display())
381+
});
382+
383+
ancestor
384+
.strip_prefix(&config.initial_sysroot)
385+
.unwrap_or_else(|_| {
386+
panic!(
387+
"Couldn’t resolve the initial relative libdir from {}",
388+
initial_target_dir.display()
389+
)
390+
})
391+
.to_path_buf()
392+
};
379393

380394
let version = std::fs::read_to_string(src.join("src").join("version"))
381395
.expect("failed to read src/version");

0 commit comments

Comments
 (0)