Configure test's unstable feature gate when built outside of bootstrap
This uses a build probe to figure out the current toolchain version - the only alternative to this is bespoke logic in Cargo to tell `test` when the toolchain is stable/unstable. The behaviour should be the same as when using `CFG_DISABLE_UNSTABLE_FEATURES` unless an arbitrary channel is provided to bootstrap, which I believe necessitates a fork anyway.
This commit is contained in:
parent
1155a30c0e
commit
dae8ea92a7
3 changed files with 16 additions and 12 deletions
11
library/test/build.rs
Normal file
11
library/test/build.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn main() {
|
||||
println!("cargo:rustc-check-cfg=cfg(enable_unstable_features)");
|
||||
|
||||
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".into());
|
||||
let version = std::process::Command::new(rustc).arg("-vV").output().unwrap();
|
||||
let stdout = String::from_utf8(version.stdout).unwrap();
|
||||
|
||||
if stdout.contains("nightly") || stdout.contains("dev") {
|
||||
println!("cargo:rustc-cfg=enable_unstable_features");
|
||||
}
|
||||
}
|
||||
|
|
@ -314,15 +314,14 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {
|
|||
Ok(test_opts)
|
||||
}
|
||||
|
||||
// FIXME: Copied from librustc_ast until linkage errors are resolved. Issue #47566
|
||||
fn is_nightly() -> bool {
|
||||
// Whether this is a feature-staged build, i.e., on the beta or stable channel
|
||||
let disable_unstable_features =
|
||||
option_env!("CFG_DISABLE_UNSTABLE_FEATURES").map(|s| s != "0").unwrap_or(false);
|
||||
// Whether we should enable unstable features for bootstrapping
|
||||
// Whether the current rustc version should allow unstable features
|
||||
let enable_unstable_features = cfg!(enable_unstable_features);
|
||||
|
||||
// The runtime override for unstable features
|
||||
let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok();
|
||||
|
||||
bootstrap || !disable_unstable_features
|
||||
bootstrap || enable_unstable_features
|
||||
}
|
||||
|
||||
// Gets the CLI options associated with `report-time` feature.
|
||||
|
|
|
|||
|
|
@ -626,12 +626,6 @@ pub fn std_cargo(
|
|||
CompilerBuiltins::BuildRustOnly => "",
|
||||
};
|
||||
|
||||
// `libtest` uses this to know whether or not to support
|
||||
// `-Zunstable-options`.
|
||||
if !builder.unstable_features() {
|
||||
cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
|
||||
}
|
||||
|
||||
for krate in crates {
|
||||
cargo.args(["-p", krate]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue