Skip to content

Commit ded2295

Browse files
authored
Merge pull request #337 from dtolnay/bootstrap
Do not rebuild on RUSTC_BOOTSTRAP changes on nightly compiler
2 parents 2d32366 + ae45b67 commit ded2295

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

build.rs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,49 @@ fn main() {
1313
let mut error_generic_member_access = false;
1414
if cfg!(feature = "std") {
1515
println!("cargo:rerun-if-changed=build/probe.rs");
16-
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
1716

18-
if compile_probe() {
17+
let consider_rustc_bootstrap;
18+
if compile_probe(false) {
19+
// This is a nightly or dev compiler, so it supports unstable
20+
// features regardless of RUSTC_BOOTSTRAP. No need to rerun build
21+
// script if RUSTC_BOOTSTRAP is changed.
22+
error_generic_member_access = true;
23+
consider_rustc_bootstrap = false;
24+
} else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") {
25+
if compile_probe(true) {
26+
// This is a stable or beta compiler for which the user has set
27+
// RUSTC_BOOTSTRAP to turn on unstable features. Rerun build
28+
// script if they change it.
29+
error_generic_member_access = true;
30+
consider_rustc_bootstrap = true;
31+
} else if rustc_bootstrap == "1" {
32+
// This compiler does not support the generic member access API
33+
// in the form that anyhow expects. No need to pay attention to
34+
// RUSTC_BOOTSTRAP.
35+
error_generic_member_access = false;
36+
consider_rustc_bootstrap = false;
37+
} else {
38+
// This is a stable or beta compiler for which RUSTC_BOOTSTRAP
39+
// is set to restrict the use of unstable features by this
40+
// crate.
41+
error_generic_member_access = false;
42+
consider_rustc_bootstrap = true;
43+
}
44+
} else {
45+
// Without RUSTC_BOOTSTRAP, this compiler does not support the
46+
// generic member access API in the form that anyhow expects, but
47+
// try again if the user turns on unstable features.
48+
error_generic_member_access = false;
49+
consider_rustc_bootstrap = true;
50+
}
51+
52+
if error_generic_member_access {
1953
println!("cargo:rustc-cfg=std_backtrace");
2054
println!("cargo:rustc-cfg=error_generic_member_access");
21-
error_generic_member_access = true;
55+
}
56+
57+
if consider_rustc_bootstrap {
58+
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
2259
}
2360
}
2461

@@ -50,7 +87,7 @@ fn main() {
5087
}
5188
}
5289

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

116+
if !rustc_bootstrap {
117+
cmd.env_remove("RUSTC_BOOTSTRAP");
118+
}
119+
79120
cmd.stderr(Stdio::null())
80121
.arg("--edition=2018")
81122
.arg("--crate-name=anyhow")

0 commit comments

Comments
 (0)