Skip to content

Commit 3f99982

Browse files
committed
Auto merge of #130739 - jieyouxu:stage0_run_make, r=Kobzol
Fix cargo staging for run-make tests Follow-up to #130642 (comment) 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.
2 parents 363ae41 + f548216 commit 3f99982

File tree

5 files changed

+78
-103
lines changed

5 files changed

+78
-103
lines changed

src/bootstrap/src/core/build_steps/test.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1730,8 +1730,23 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17301730
let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
17311731

17321732
if mode == "run-make" {
1733-
let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
1734-
cmd.arg("--cargo-path").arg(cargo);
1733+
let cargo_path = if builder.top_stage == 0 {
1734+
// If we're using `--stage 0`, we should provide the bootstrap cargo.
1735+
builder.initial_cargo.clone()
1736+
} else {
1737+
// We need to properly build cargo using the suitable stage compiler.
1738+
1739+
// HACK: currently tool stages are off-by-one compared to compiler stages, i.e. if
1740+
// you give `tool::Cargo` a stage 1 rustc, it will cause stage 2 rustc to be built
1741+
// and produce a cargo built with stage 2 rustc. To fix this, we need to chop off
1742+
// the compiler stage by 1 to align with expected `./x test run-make --stage N`
1743+
// behavior, i.e. we need to pass `N - 1` compiler stage to cargo. See also Miri
1744+
// which does a similar hack.
1745+
let compiler = builder.compiler(builder.top_stage - 1, compiler.host);
1746+
builder.ensure(tool::Cargo { compiler, target: compiler.host })
1747+
};
1748+
1749+
cmd.arg("--cargo-path").arg(cargo_path);
17351750
}
17361751

17371752
// 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
20882103
cmd.arg("--rustfix-coverage");
20892104
}
20902105

2091-
cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
2092-
20932106
cmd.arg("--channel").arg(&builder.config.channel);
20942107

20952108
if !builder.config.omit_git_hash {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::command::Command;
22
use crate::env_var;
33

4-
/// Returns a command that can be used to invoke Cargo.
4+
/// Returns a command that can be used to invoke cargo. The cargo is provided by compiletest
5+
/// through the `CARGO` env var.
56
pub fn cargo() -> Command {
6-
Command::new(env_var("BOOTSTRAP_CARGO"))
7+
Command::new(env_var("CARGO"))
78
}

tests/run-make/compiler-builtins/rmake.rs

+23-33
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,36 @@
1515
#![deny(warnings)]
1616

1717
use std::collections::HashSet;
18-
use std::path::PathBuf;
1918

2019
use run_make_support::object::read::Object;
2120
use run_make_support::object::read::archive::ArchiveFile;
2221
use run_make_support::object::{ObjectSection, ObjectSymbol, RelocationTarget};
2322
use run_make_support::rfs::{read, read_dir};
24-
use run_make_support::{cmd, env_var, object};
23+
use run_make_support::{cargo, object, path, target};
2524

2625
fn main() {
27-
let target_dir = PathBuf::from("target");
28-
let target = env_var("TARGET");
29-
30-
println!("Testing compiler_builtins for {}", target);
31-
32-
let manifest_path = PathBuf::from("Cargo.toml");
33-
34-
let path = env_var("PATH");
35-
let rustc = env_var("RUSTC");
36-
let cargo = env_var("CARGO");
37-
let mut cmd = cmd(cargo);
38-
cmd.args(&[
39-
"build",
40-
"--manifest-path",
41-
manifest_path.to_str().unwrap(),
42-
"-Zbuild-std=core",
43-
"--target",
44-
&target,
45-
])
46-
.env("PATH", path)
47-
.env("RUSTC", rustc)
48-
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes")
49-
.env("CARGO_TARGET_DIR", &target_dir)
50-
.env("RUSTC_BOOTSTRAP", "1")
51-
// Visual Studio 2022 requires that the LIB env var be set so it can
52-
// find the Windows SDK.
53-
.env("LIB", std::env::var("LIB").unwrap_or_default());
54-
55-
cmd.run();
56-
57-
let rlibs_path = target_dir.join(target).join("debug").join("deps");
26+
let target_dir = path("target");
27+
28+
println!("Testing compiler_builtins for {}", target());
29+
30+
cargo()
31+
.args(&[
32+
"build",
33+
"--manifest-path",
34+
"Cargo.toml",
35+
"-Zbuild-std=core",
36+
"--target",
37+
&target(),
38+
])
39+
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes")
40+
.env("CARGO_TARGET_DIR", &target_dir)
41+
.env("RUSTC_BOOTSTRAP", "1")
42+
// Visual Studio 2022 requires that the LIB env var be set so it can
43+
// find the Windows SDK.
44+
.env("LIB", std::env::var("LIB").unwrap_or_default())
45+
.run();
46+
47+
let rlibs_path = target_dir.join(target()).join("debug").join("deps");
5848
let compiler_builtins_rlib = read_dir(rlibs_path)
5949
.find_map(|e| {
6050
let path = e.unwrap().path();

tests/run-make/thumb-none-cortex-m/rmake.rs

+16-30
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
1515
//@ only-thumb
1616

17-
use std::path::PathBuf;
18-
19-
use run_make_support::rfs::create_dir;
20-
use run_make_support::{cmd, env_var, target};
17+
use run_make_support::{cargo, cmd, env, env_var, target};
2118

2219
const CRATE: &str = "cortex-m";
2320
const CRATE_URL: &str = "https://github.com/rust-embedded/cortex-m";
@@ -28,32 +25,21 @@ fn main() {
2825
// See below link for git usage:
2926
// https://stackoverflow.com/questions/3489173#14091182
3027
cmd("git").args(["clone", CRATE_URL, CRATE]).run();
31-
std::env::set_current_dir(CRATE).unwrap();
28+
env::set_current_dir(CRATE);
3229
cmd("git").args(["reset", "--hard", CRATE_SHA1]).run();
3330

34-
let target_dir = PathBuf::from("target");
35-
let manifest_path = PathBuf::from("Cargo.toml");
36-
37-
let path = env_var("PATH");
38-
let rustc = env_var("RUSTC");
39-
let cargo = env_var("CARGO");
40-
// FIXME: extract cargo invocations to a proper command
41-
// https://github.com/rust-lang/rust/issues/128734
42-
let mut cmd = cmd(cargo);
43-
cmd.args(&[
44-
"build",
45-
"--manifest-path",
46-
manifest_path.to_str().unwrap(),
47-
"-Zbuild-std=core",
48-
"--target",
49-
&target(),
50-
])
51-
.env("PATH", path)
52-
.env("RUSTC", rustc)
53-
.env("CARGO_TARGET_DIR", &target_dir)
54-
// Don't make lints fatal, but they need to at least warn
55-
// or they break Cargo's target info parsing.
56-
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes --cap-lints=warn");
57-
58-
cmd.run();
31+
cargo()
32+
.args(&[
33+
"build",
34+
"--manifest-path",
35+
"Cargo.toml",
36+
"-Zbuild-std=core",
37+
"--target",
38+
&target(),
39+
])
40+
.env("CARGO_TARGET_DIR", "target")
41+
// Don't make lints fatal, but they need to at least warn
42+
// or they break Cargo's target info parsing.
43+
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes --cap-lints=warn")
44+
.run();
5945
}

tests/run-make/thumb-none-qemu/rmake.rs

+19-34
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,34 @@
1414
//!
1515
//! FIXME: https://github.com/rust-lang/rust/issues/128733 this test uses external
1616
//! dependencies, and needs an active internet connection
17-
//!
18-
//! FIXME: https://github.com/rust-lang/rust/issues/128734 extract bootstrap cargo
19-
//! to a proper command
2017
2118
//@ only-thumb
2219

2320
use std::path::PathBuf;
2421

25-
use run_make_support::{cmd, env_var, path_helpers, target};
22+
use run_make_support::{cargo, cmd, env_var, path, target};
2623

2724
const CRATE: &str = "example";
2825

2926
fn main() {
3027
std::env::set_current_dir(CRATE).unwrap();
3128

32-
let bootstrap_cargo = env_var("BOOTSTRAP_CARGO");
33-
let path = env_var("PATH");
34-
let rustc = env_var("RUSTC");
35-
36-
let target_dir = path_helpers::path("target");
37-
let manifest_path = path_helpers::path("Cargo.toml");
38-
39-
let debug = {
40-
let mut cmd = cmd(&bootstrap_cargo);
41-
cmd.args(&["run", "--target", &target()])
42-
.env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
43-
.env("CARGO_TARGET_DIR", &target_dir)
44-
.env("PATH", &path)
45-
.env("RUSTC", &rustc);
46-
cmd.run()
47-
};
48-
49-
debug.assert_stdout_contains("x = 42");
50-
51-
let release = {
52-
let mut cmd = cmd(&bootstrap_cargo);
53-
cmd.args(&["run", "--release", "--target", &target()])
54-
.env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
55-
.env("CARGO_TARGET_DIR", &target_dir)
56-
.env("PATH", &path)
57-
.env("RUSTC", &rustc);
58-
cmd.run()
59-
};
60-
61-
release.assert_stdout_contains("x = 42");
29+
let target_dir = path("target");
30+
let manifest_path = path("Cargo.toml");
31+
32+
// Debug
33+
cargo()
34+
.args(&["run", "--target", &target()])
35+
.env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
36+
.env("CARGO_TARGET_DIR", &target_dir)
37+
.run()
38+
.assert_stdout_contains("x = 42");
39+
40+
// Release
41+
cargo()
42+
.args(&["run", "--release", "--target", &target()])
43+
.env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x")
44+
.env("CARGO_TARGET_DIR", &target_dir)
45+
.run()
46+
.assert_stdout_contains("x = 42");
6247
}

0 commit comments

Comments
 (0)