Skip to content

Commit

Permalink
Merge pull request #274 from dtolnay/bootstrap
Browse files Browse the repository at this point in the history
Do not rebuild on RUSTC_BOOTSTRAP changes on nightly compiler
  • Loading branch information
dtolnay authored Dec 30, 2023
2 parents 5fd9537 + f334cfc commit 0e280fe
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,51 @@ use std::path::Path;
use std::process::{self, Command, Stdio};

fn main() {
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
let error_generic_member_access;
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 thiserror 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 thiserror expects, but try again
// if the user turns on unstable features.
error_generic_member_access = false;
consider_rustc_bootstrap = true;
}

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

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

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 @@ -37,6 +74,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=thiserror")
Expand Down

0 comments on commit 0e280fe

Please sign in to comment.