Skip to content
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

Do not rebuild on RUSTC_BOOTSTRAP changes on nightly compiler #274

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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