about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-01 13:09:56 +0000
committerbors <bors@rust-lang.org>2024-12-01 13:09:56 +0000
commitca4e54f032a49a23883c429ab34911ed856973c2 (patch)
treec0a3d8f39ac811efb12f29eac5a8f242d98fb0dc /src/bootstrap
parent6c76ed5503966c39381fac64eb905ac45e346695 (diff)
parentdd2ac08cfefd66cf827b1ced863d98cc7f09d279 (diff)
downloadrust-ca4e54f032a49a23883c429ab34911ed856973c2.tar.gz
rust-ca4e54f032a49a23883c429ab34911ed856973c2.zip
Auto merge of #132390 - RalfJung:diagnostics-root-dir, r=albertlarsan68,weihanglo
bootstrap: show diagnostics relative to rustc src dir

Fixes https://github.com/rust-lang/rust/issues/128726

Depends on https://github.com/rust-lang/cargo/pull/14752 propagating to bootstrap cargo
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/bootstrap.py3
-rw-r--r--src/bootstrap/src/core/build_steps/test.rs7
-rw-r--r--src/bootstrap/src/core/builder/cargo.rs3
3 files changed, 9 insertions, 4 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index d7ae0299dd6..762f4e653e9 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -1029,7 +1029,8 @@ class RustBuild(object):
             raise Exception("no cargo executable found at `{}`".format(
                 self.cargo()))
         args = [self.cargo(), "build", "--manifest-path",
-                os.path.join(self.rust_root, "src/bootstrap/Cargo.toml")]
+                os.path.join(self.rust_root, "src/bootstrap/Cargo.toml"),
+                "-Zroot-dir="+self.rust_root]
         args.extend("--verbose" for _ in range(self.verbose))
         if self.use_locked_deps:
             args.append("--locked")
diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs
index f670452f4ef..4fa91c1a571 100644
--- a/src/bootstrap/src/core/build_steps/test.rs
+++ b/src/bootstrap/src/core/build_steps/test.rs
@@ -305,9 +305,10 @@ impl Step for Cargo {
         // those features won't be able to land.
         cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
         cargo.env("PATH", path_for_cargo(builder, compiler));
-        // Cargo's test suite requires configurations from its own `.cargo/config.toml`.
-        // Change to the directory so Cargo can read from it.
-        cargo.current_dir(builder.src.join(Self::CRATE_PATH));
+        // Cargo's test suite uses `CARGO_RUSTC_CURRENT_DIR` to determine the path that `file!` is
+        // relative to. Cargo no longer sets this env var, so we have to do that. This has to be the
+        // same value as `-Zroot-dir`.
+        cargo.env("CARGO_RUSTC_CURRENT_DIR", builder.src.display().to_string());
 
         #[cfg(feature = "build-metrics")]
         builder.metrics.begin_test_suite(
diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs
index 0688a1d6892..dd138508bea 100644
--- a/src/bootstrap/src/core/builder/cargo.rs
+++ b/src/bootstrap/src/core/builder/cargo.rs
@@ -703,6 +703,9 @@ impl Builder<'_> {
 
         cargo.arg("-j").arg(self.jobs().to_string());
 
+        // Make cargo emit diagnostics relative to the rustc src dir.
+        cargo.arg(format!("-Zroot-dir={}", self.src.display()));
+
         // FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
         // Force cargo to output binaries with disambiguating hashes in the name
         let mut metadata = if compiler.stage == 0 {