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.
This commit is contained in:
bors
2024-09-24 22:51:43 +00:00
5 changed files with 73 additions and 98 deletions
+17 -4
View File
@@ -1730,8 +1730,23 @@ fn run(self, builder: &Builder<'_>) {
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 @@ fn run(self, builder: &Builder<'_>) {
cmd.arg("--rustfix-coverage");
}
cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
cmd.arg("--channel").arg(&builder.config.channel);
if !builder.config.omit_git_hash {
@@ -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"))
}