about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-24 22:51:43 +0000
committerbors <bors@rust-lang.org>2024-09-24 22:51:43 +0000
commit3f99982c633dbca746140db60ed52ba7fa112803 (patch)
tree6421e88cf01795dd9d63bdf9531d8985ff9daa23 /src
parent363ae4188316b8b22cf6c1890bc73d84d05f70a4 (diff)
parentf5482167286424fd25266d8202e8ded6655cc9ec (diff)
downloadrust-3f99982c633dbca746140db60ed52ba7fa112803.tar.gz
rust-3f99982c633dbca746140db60ed52ba7fa112803.zip
Auto merge of #130739 - jieyouxu:stage0_run_make, r=Kobzol
Fix cargo staging for run-make tests

Follow-up to https://github.com/rust-lang/rust/pull/130642#issuecomment-2366891866 to make sure that when

```
$ COMPILETEST_FORCE_STAGE0=1 ./x test run-make --stage 0
```

is used, bootstrap cargo is used in order to avoid building stage 1 rustc. Note that run-make tests are usually not written with `--stage 0` in mind and some tests may rely on stage1 rustc (nightly) behavior, and it is expected that some tests will fail under this invocation.

This PR also fixes `tool::Cargo` staging in compiletest when preparing for `run-make` test mode, by chopping off a stage from the `compiler` passed to `tool::Cargo` such that when the user invokes with stage `N`

```
./x test run-make --stage N
```

the `run-make` test suite will be tested against the cargo built by stage `N` compiler. Let's take `N=1`, i.e. `--stage 1`, without chopping off a stage, previously `./x test run-make --stage 1` will cause stage 1 rustc + std to be built, then stage 2 rustc, and cargo will be produced by the stage 2 rustc, which is clearly not what we want. By chopping off a stage, it means that cargo will be produced by the stage 1 rustc.

cc #119946, #59864.
See discussions regarding the tool staging at https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/.E2.9C.94.20stage1.20run-make.20tests.20now.20need.20stage2.20rustc.20built.20for.20c.2E.2E.2E.
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/src/core/build_steps/test.rs21
-rw-r--r--src/tools/run-make-support/src/external_deps/cargo.rs5
2 files changed, 20 insertions, 6 deletions
diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs
index 8f076e5554e..870fe6a9f16 100644
--- a/src/bootstrap/src/core/build_steps/test.rs
+++ b/src/bootstrap/src/core/build_steps/test.rs
@@ -1730,8 +1730,23 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
         let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
 
         if mode == "run-make" {
-            let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
-            cmd.arg("--cargo-path").arg(cargo);
+            let cargo_path = if builder.top_stage == 0 {
+                // If we're using `--stage 0`, we should provide the bootstrap cargo.
+                builder.initial_cargo.clone()
+            } else {
+                // We need to properly build cargo using the suitable stage compiler.
+
+                // HACK: currently tool stages are off-by-one compared to compiler stages, i.e. if
+                // you give `tool::Cargo` a stage 1 rustc, it will cause stage 2 rustc to be built
+                // and produce a cargo built with stage 2 rustc. To fix this, we need to chop off
+                // the compiler stage by 1 to align with expected `./x test run-make --stage N`
+                // behavior, i.e. we need to pass `N - 1` compiler stage to cargo. See also Miri
+                // which does a similar hack.
+                let compiler = builder.compiler(builder.top_stage - 1, compiler.host);
+                builder.ensure(tool::Cargo { compiler, target: compiler.host })
+            };
+
+            cmd.arg("--cargo-path").arg(cargo_path);
         }
 
         // Avoid depending on rustdoc when we don't need it.
@@ -2088,8 +2103,6 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
             cmd.arg("--rustfix-coverage");
         }
 
-        cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
-
         cmd.arg("--channel").arg(&builder.config.channel);
 
         if !builder.config.omit_git_hash {
diff --git a/src/tools/run-make-support/src/external_deps/cargo.rs b/src/tools/run-make-support/src/external_deps/cargo.rs
index b0e045dc80b..e91d101cb99 100644
--- a/src/tools/run-make-support/src/external_deps/cargo.rs
+++ b/src/tools/run-make-support/src/external_deps/cargo.rs
@@ -1,7 +1,8 @@
 use crate::command::Command;
 use crate::env_var;
 
-/// Returns a command that can be used to invoke Cargo.
+/// Returns a command that can be used to invoke cargo. The cargo is provided by compiletest
+/// through the `CARGO` env var.
 pub fn cargo() -> Command {
-    Command::new(env_var("BOOTSTRAP_CARGO"))
+    Command::new(env_var("CARGO"))
 }