Skip to content

Commit 25a7d2d

Browse files
committed
Fix cargo run tidy
When I implemented rust-only bootstrapping in #92260, I neglected to test stage0 tools - it turns out they were broken because they couldn't find the sysroot of the initial bootstrap compiler. This fixes stage0 tools by using `rustc --print sysroot` instead of assuming rustc is already in a sysroot and hard-coding the relative directory.
1 parent 687e53e commit 25a7d2d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/bootstrap/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ use std::os::unix::fs::symlink as symlink_file;
117117
use std::os::windows::fs::symlink_file;
118118

119119
use filetime::FileTime;
120+
use once_cell::sync::OnceCell;
120121

121122
use crate::builder::Kind;
122123
use crate::config::{LlvmLibunwind, TargetSelection};
@@ -892,7 +893,12 @@ impl Build {
892893

893894
/// Returns the sysroot of the snapshot compiler.
894895
fn rustc_snapshot_sysroot(&self) -> &Path {
895-
self.initial_rustc.parent().unwrap().parent().unwrap()
896+
static SYSROOT_CACHE: OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
897+
SYSROOT_CACHE.get_or_init(|| {
898+
let mut rustc = Command::new(&self.initial_rustc);
899+
rustc.args(&["--print", "sysroot"]);
900+
output(&mut rustc).trim().into()
901+
})
896902
}
897903

898904
/// Runs a command, printing out nice contextual information if it fails.

0 commit comments

Comments
 (0)