Skip to content

Commit

Permalink
Rollup merge of rust-lang#94806 - jyn514:cargo-run-tidy, r=Mark-Simul…
Browse files Browse the repository at this point in the history
…acrum

Fix `cargo run tidy`

When I implemented rust-only bootstrapping in rust-lang#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 rust-lang#94797 (properly, without having to change rustup).
  • Loading branch information
Dylan-DPC committed Mar 30, 2022
2 parents 3e75146 + 25a7d2d commit 3b851de
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ use std::os::unix::fs::symlink as symlink_file;
use std::os::windows::fs::symlink_file;

use filetime::FileTime;
use once_cell::sync::OnceCell;

use crate::builder::Kind;
use crate::config::{LlvmLibunwind, TargetSelection};
Expand Down Expand Up @@ -904,7 +905,12 @@ impl Build {

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

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

0 comments on commit 3b851de

Please sign in to comment.