about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-03-31 00:26:28 +0200
committerGitHub <noreply@github.com>2022-03-31 00:26:28 +0200
commit943ea7fae53ac71cd8ddf5c215a750c9ab616eee (patch)
treedc090162ec93e02f703b4c55bcab3dd7f3fe2751
parentb75f384d0b0227000eff393e5d4e11bda56b293f (diff)
parent25a7d2d540656e0499a43bfd01243250f2a25d7a (diff)
downloadrust-943ea7fae53ac71cd8ddf5c215a750c9ab616eee.tar.gz
rust-943ea7fae53ac71cd8ddf5c215a750c9ab616eee.zip
Rollup merge of #94806 - jyn514:cargo-run-tidy, r=Mark-Simulacrum
Fix `cargo run tidy`

When I implemented rust-only bootstrapping in https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/issues/94797 (properly, without having to change rustup).
-rw-r--r--src/bootstrap/lib.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 8f076ad914d..570a61742bc 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -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};
@@ -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.