[go: nahoru, domu]

Skip to content

Commit

Permalink
Do not rebuild on RUSTC_BOOTSTRAP changes on nightly compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 30, 2023
1 parent 2d32366 commit ae45b67
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,49 @@ fn main() {
let mut error_generic_member_access = false;
if cfg!(feature = "std") {
println!("cargo:rerun-if-changed=build/probe.rs");
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");

if compile_probe() {
let consider_rustc_bootstrap;
if compile_probe(false) {
// This is a nightly or dev compiler, so it supports unstable
// features regardless of RUSTC_BOOTSTRAP. No need to rerun build
// script if RUSTC_BOOTSTRAP is changed.
error_generic_member_access = true;
consider_rustc_bootstrap = false;
} else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") {
if compile_probe(true) {
// This is a stable or beta compiler for which the user has set
// RUSTC_BOOTSTRAP to turn on unstable features. Rerun build
// script if they change it.
error_generic_member_access = true;
consider_rustc_bootstrap = true;
} else if rustc_bootstrap == "1" {
// This compiler does not support the generic member access API
// in the form that anyhow expects. No need to pay attention to
// RUSTC_BOOTSTRAP.
error_generic_member_access = false;
consider_rustc_bootstrap = false;
} else {
// This is a stable or beta compiler for which RUSTC_BOOTSTRAP
// is set to restrict the use of unstable features by this
// crate.
error_generic_member_access = false;
consider_rustc_bootstrap = true;
}
} else {
// Without RUSTC_BOOTSTRAP, this compiler does not support the
// generic member access API in the form that anyhow expects, but
// try again if the user turns on unstable features.
error_generic_member_access = false;
consider_rustc_bootstrap = true;
}

if error_generic_member_access {
println!("cargo:rustc-cfg=std_backtrace");
println!("cargo:rustc-cfg=error_generic_member_access");
error_generic_member_access = true;
}

if consider_rustc_bootstrap {
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
}
}

Expand Down Expand Up @@ -50,7 +87,7 @@ fn main() {
}
}

fn compile_probe() -> bool {
fn compile_probe(rustc_bootstrap: bool) -> bool {
if env::var_os("RUSTC_STAGE").is_some() {
// We are running inside rustc bootstrap. This is a highly non-standard
// environment with issues such as:
Expand All @@ -76,6 +113,10 @@ fn compile_probe() -> bool {
Command::new(rustc)
};

if !rustc_bootstrap {
cmd.env_remove("RUSTC_BOOTSTRAP");
}

cmd.stderr(Stdio::null())
.arg("--edition=2018")
.arg("--crate-name=anyhow")
Expand Down

0 comments on commit ae45b67

Please sign in to comment.