Skip to content

Commit d17e0cf

Browse files
authored
Rollup merge of rust-lang#126476 - ferrocene:pa-bootstrap-test-local-rustc, r=onur-ozkan
Fix running bootstrap tests with a local Rust toolchain as the stage0 When configuring a local Rust toolchain as the stage0 (with `build.rustc` and `build.cargo` in `config.toml`) we noticed there were test failures (both on the Python and the Rust side) due to bootstrap not being able to find rustc and Cargo. This was due to those two `config.toml` settings not being propagated in the tests. This PR fixes the issue by ensuring rustc and cargo are always configured in tests, using the parent bootstrap's `initial_rustc` and `initial_cargo`. try-job: x86_64-msvc Fixes rust-lang#105766
2 parents b215beb + 9cd1d25 commit d17e0cf

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/bootstrap/bootstrap_test.py

+19
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ def build_args(self, configure_args=None, args=None, env=None):
138138
if env is None:
139139
env = {}
140140

141+
# This test ends up invoking build_bootstrap_cmd, which searches for
142+
# the Cargo binary and errors out if it cannot be found. This is not a
143+
# problem in most cases, but there is a scenario where it would cause
144+
# the test to fail.
145+
#
146+
# When a custom local Cargo is configured in config.toml (with the
147+
# build.cargo setting), no Cargo is downloaded to any location known by
148+
# bootstrap, and bootstrap relies on that setting to find it.
149+
#
150+
# In this test though we are not using the config.toml of the caller:
151+
# we are generating a blank one instead. If we don't set build.cargo in
152+
# it, the test will have no way to find Cargo, failing the test.
153+
cargo_bin = os.environ.get("BOOTSTRAP_TEST_CARGO_BIN")
154+
if cargo_bin is not None:
155+
configure_args += ["--set", "build.cargo=" + cargo_bin]
156+
rustc_bin = os.environ.get("BOOTSTRAP_TEST_RUSTC_BIN")
157+
if rustc_bin is not None:
158+
configure_args += ["--set", "build.rustc=" + rustc_bin]
159+
141160
env = env.copy()
142161
env["PATH"] = os.environ["PATH"]
143162

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

+2
Original file line numberDiff line numberDiff line change
@@ -2979,6 +2979,8 @@ impl Step for Bootstrap {
29792979
.args(["-m", "unittest", "bootstrap_test.py"])
29802980
.env("BUILD_DIR", &builder.out)
29812981
.env("BUILD_PLATFORM", builder.build.build.triple)
2982+
.env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc)
2983+
.env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo)
29822984
.current_dir(builder.src.join("src/bootstrap/"));
29832985
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
29842986
// Use `python -m unittest` manually if you want to pass arguments.

src/bootstrap/src/core/config/config.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,17 @@ impl Config {
13301330
TomlConfig::default()
13311331
};
13321332

1333+
if cfg!(test) {
1334+
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
1335+
// same ones used to call the tests (if custom ones are not defined in the toml). If we
1336+
// don't do that, bootstrap will use its own detection logic to find a suitable rustc
1337+
// and Cargo, which doesn't work when the caller is specìfying a custom local rustc or
1338+
// Cargo in their config.toml.
1339+
let build = toml.build.get_or_insert_with(Default::default);
1340+
build.rustc = build.rustc.take().or(std::env::var_os("RUSTC").map(|p| p.into()));
1341+
build.cargo = build.cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
1342+
}
1343+
13331344
if let Some(include) = &toml.profile {
13341345
// Allows creating alias for profile names, allowing
13351346
// profiles to be renamed while maintaining back compatibility
@@ -1448,7 +1459,12 @@ impl Config {
14481459
rustc
14491460
} else {
14501461
config.download_beta_toolchain();
1451-
config.out.join(config.build.triple).join("stage0/bin/rustc")
1462+
config
1463+
.out
1464+
.join(config.build.triple)
1465+
.join("stage0")
1466+
.join("bin")
1467+
.join(exe("rustc", config.build))
14521468
};
14531469

14541470
config.initial_cargo = if let Some(cargo) = cargo {
@@ -1458,7 +1474,12 @@ impl Config {
14581474
cargo
14591475
} else {
14601476
config.download_beta_toolchain();
1461-
config.out.join(config.build.triple).join("stage0/bin/cargo")
1477+
config
1478+
.out
1479+
.join(config.build.triple)
1480+
.join("stage0")
1481+
.join("bin")
1482+
.join(exe("cargo", config.build))
14621483
};
14631484

14641485
// NOTE: it's important this comes *after* we set `initial_rustc` just above.

0 commit comments

Comments
 (0)