Skip to content

Commit

Permalink
Rollup merge of #126476 - ferrocene:pa-bootstrap-test-local-rustc, r=…
Browse files Browse the repository at this point in the history
…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`.
  • Loading branch information
matthiaskrgr authored Jun 14, 2024
2 parents 04b3114 + fcb6ff5 commit d97c040
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ def build_args(self, configure_args=None, args=None, env=None):
if env is None:
env = {}

# This test ends up invoking build_bootstrap_cmd, which searches for
# the Cargo binary and errors out if it cannot be found. This is not a
# problem in most cases, but there is a scenario where it would cause
# the test to fail.
#
# When a custom local Cargo is configured in config.toml (with the
# build.cargo setting), no Cargo is downloaded to any location known by
# bootstrap, and bootstrap relies on that setting to find it.
#
# In this test though we are not using the config.toml of the caller:
# we are generating a blank one instead. If we don't set build.cargo in
# it, the test will have no way to find Cargo, failing the test.
cargo_bin = os.environ.get("BOOTSTRAP_TEST_CARGO_BIN")
if cargo_bin is not None:
configure_args += ["--set", "build.cargo=" + cargo_bin]
rustc_bin = os.environ.get("BOOTSTRAP_TEST_RUSTC_BIN")
if rustc_bin is not None:
configure_args += ["--set", "build.rustc=" + rustc_bin]

env = env.copy()
env["PATH"] = os.environ["PATH"]

Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,8 @@ impl Step for Bootstrap {
.args(["-m", "unittest", "bootstrap_test.py"])
.env("BUILD_DIR", &builder.out)
.env("BUILD_PLATFORM", builder.build.build.triple)
.env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc)
.env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo)
.current_dir(builder.src.join("src/bootstrap/"));
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
// Use `python -m unittest` manually if you want to pass arguments.
Expand Down
14 changes: 13 additions & 1 deletion src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,19 @@ impl Config {
pub fn parse(args: &[String]) -> Config {
#[cfg(test)]
fn get_toml(_: &Path) -> TomlConfig {
TomlConfig::default()
let mut default = TomlConfig::default();

// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
// same ones used to call the tests. If we don't do that, bootstrap will use its own
// detection logic to find a suitable rustc and Cargo, which doesn't work when the
// caller is specìfying a custom local rustc or Cargo in their config.toml.
default.build = Some(Build {
rustc: std::env::var_os("RUSTC").map(|v| v.into()),
cargo: std::env::var_os("CARGO").map(|v| v.into()),
..Build::default()
});

default
}

#[cfg(not(test))]
Expand Down

0 comments on commit d97c040

Please sign in to comment.