@@ -4,14 +4,51 @@ use std::path::Path;
44use std:: process:: { self , Command , Stdio } ;
55
66fn main ( ) {
7- println ! ( "cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP" ) ;
7+ let error_generic_member_access;
8+ let consider_rustc_bootstrap;
9+ if compile_probe ( false ) {
10+ // This is a nightly or dev compiler, so it supports unstable features
11+ // regardless of RUSTC_BOOTSTRAP. No need to rerun build script if
12+ // RUSTC_BOOTSTRAP is changed.
13+ error_generic_member_access = true ;
14+ consider_rustc_bootstrap = false ;
15+ } else if let Some ( rustc_bootstrap) = env:: var_os ( "RUSTC_BOOTSTRAP" ) {
16+ if compile_probe ( true ) {
17+ // This is a stable or beta compiler for which the user has set
18+ // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build script
19+ // if they change it.
20+ error_generic_member_access = true ;
21+ consider_rustc_bootstrap = true ;
22+ } else if rustc_bootstrap == "1" {
23+ // This compiler does not support the generic member access API in
24+ // the form that thiserror expects. No need to pay attention to
25+ // RUSTC_BOOTSTRAP.
26+ error_generic_member_access = false ;
27+ consider_rustc_bootstrap = false ;
28+ } else {
29+ // This is a stable or beta compiler for which RUSTC_BOOTSTRAP is
30+ // set to restrict the use of unstable features by this crate.
31+ error_generic_member_access = false ;
32+ consider_rustc_bootstrap = true ;
33+ }
34+ } else {
35+ // Without RUSTC_BOOTSTRAP, this compiler does not support the generic
36+ // member access API in the form that thiserror expects, but try again
37+ // if the user turns on unstable features.
38+ error_generic_member_access = false ;
39+ consider_rustc_bootstrap = true ;
40+ }
841
9- if compile_probe ( ) {
42+ if error_generic_member_access {
1043 println ! ( "cargo:rustc-cfg=error_generic_member_access" ) ;
1144 }
45+
46+ if consider_rustc_bootstrap {
47+ println ! ( "cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP" ) ;
48+ }
1249}
1350
14- fn compile_probe ( ) -> bool {
51+ fn compile_probe ( rustc_bootstrap : bool ) -> bool {
1552 if env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) {
1653 // We are running inside rustc bootstrap. This is a highly non-standard
1754 // environment with issues such as:
@@ -37,6 +74,10 @@ fn compile_probe() -> bool {
3774 Command :: new ( rustc)
3875 } ;
3976
77+ if !rustc_bootstrap {
78+ cmd. env_remove ( "RUSTC_BOOTSTRAP" ) ;
79+ }
80+
4081 cmd. stderr ( Stdio :: null ( ) )
4182 . arg ( "--edition=2018" )
4283 . arg ( "--crate-name=thiserror" )
0 commit comments