Skip to content

Commit d97c040

Browse files
authored
Rollup merge of #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`.
2 parents 04b3114 + fcb6ff5 commit d97c040

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
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
@@ -3040,6 +3040,8 @@ impl Step for Bootstrap {
30403040
.args(["-m", "unittest", "bootstrap_test.py"])
30413041
.env("BUILD_DIR", &builder.out)
30423042
.env("BUILD_PLATFORM", builder.build.build.triple)
3043+
.env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc)
3044+
.env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo)
30433045
.current_dir(builder.src.join("src/bootstrap/"));
30443046
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
30453047
// Use `python -m unittest` manually if you want to pass arguments.

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,19 @@ impl Config {
11891189
pub fn parse(args: &[String]) -> Config {
11901190
#[cfg(test)]
11911191
fn get_toml(_: &Path) -> TomlConfig {
1192-
TomlConfig::default()
1192+
let mut default = TomlConfig::default();
1193+
1194+
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
1195+
// same ones used to call the tests. If we don't do that, bootstrap will use its own
1196+
// detection logic to find a suitable rustc and Cargo, which doesn't work when the
1197+
// caller is specìfying a custom local rustc or Cargo in their config.toml.
1198+
default.build = Some(Build {
1199+
rustc: std::env::var_os("RUSTC").map(|v| v.into()),
1200+
cargo: std::env::var_os("CARGO").map(|v| v.into()),
1201+
..Build::default()
1202+
});
1203+
1204+
default
11931205
}
11941206

11951207
#[cfg(not(test))]

0 commit comments

Comments
 (0)