Skip to content

Properly pass path to staged rustc to compiletest self-tests #144782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,12 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
SourceType::InTree,
&[],
);

// Used for `compiletest` self-tests to have the path to the *staged* compiler. Getting this
// right is important, as `compiletest` is intended to only support one target spec JSON
// format, namely that of the staged compiler.
cargo.env("TEST_RUSTC", builder.rustc(compiler));

cargo.allow_features(COMPILETEST_ALLOW_FEATURES);
run_cargo_test(cargo, &[], &[], "compiletest self test", host, builder);
}
Expand Down
18 changes: 2 additions & 16 deletions src/tools/compiletest/src/directives/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,8 @@ impl ConfigBuilder {
}

args.push("--rustc-path".to_string());
// This is a subtle/fragile thing. On rust-lang CI, there is no global
// `rustc`, and Cargo doesn't offer a convenient way to get the path to
// `rustc`. Fortunately bootstrap sets `RUSTC` for us, which is pointing
// to the stage0 compiler.
//
// Otherwise, if you are running compiletests's tests manually, you
// probably don't have `RUSTC` set, in which case this falls back to the
// global rustc. If your global rustc is too far out of sync with stage0,
// then this may cause confusing errors. Or if for some reason you don't
// have rustc in PATH, that would also fail.
args.push(std::env::var("RUSTC").unwrap_or_else(|_| {
eprintln!(
"warning: RUSTC not set, using global rustc (are you not running via bootstrap?)"
);
"rustc".to_string()
}));
args.push(std::env::var("TEST_RUSTC").expect("must be configured by bootstrap"));

crate::parse_config(args)
}
}
Expand Down
Loading