Skip to content

Commit 943ea7f

Browse files
authored
Rollup merge of #94806 - jyn514:cargo-run-tidy, r=Mark-Simulacrum
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. Fixes #94797 (properly, without having to change rustup).
2 parents b75f384 + 25a7d2d commit 943ea7f

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};
@@ -904,7 +905,12 @@ impl Build {
904905

905906
/// Returns the sysroot of the snapshot compiler.
906907
fn rustc_snapshot_sysroot(&self) -> &Path {
907-
self.initial_rustc.parent().unwrap().parent().unwrap()
908+
static SYSROOT_CACHE: OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
909+
SYSROOT_CACHE.get_or_init(|| {
910+
let mut rustc = Command::new(&self.initial_rustc);
911+
rustc.args(&["--print", "sysroot"]);
912+
output(&mut rustc).trim().into()
913+
})
908914
}
909915

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

0 commit comments

Comments
 (0)