@@ -4,14 +4,51 @@ use std::path::Path;
4
4
use std:: process:: { self , Command , Stdio } ;
5
5
6
6
fn 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
+ }
8
41
9
- if compile_probe ( ) {
42
+ if error_generic_member_access {
10
43
println ! ( "cargo:rustc-cfg=error_generic_member_access" ) ;
11
44
}
45
+
46
+ if consider_rustc_bootstrap {
47
+ println ! ( "cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP" ) ;
48
+ }
12
49
}
13
50
14
- fn compile_probe ( ) -> bool {
51
+ fn compile_probe ( rustc_bootstrap : bool ) -> bool {
15
52
if env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) {
16
53
// We are running inside rustc bootstrap. This is a highly non-standard
17
54
// environment with issues such as:
@@ -37,6 +74,10 @@ fn compile_probe() -> bool {
37
74
Command :: new ( rustc)
38
75
} ;
39
76
77
+ if !rustc_bootstrap {
78
+ cmd. env_remove ( "RUSTC_BOOTSTRAP" ) ;
79
+ }
80
+
40
81
cmd. stderr ( Stdio :: null ( ) )
41
82
. arg ( "--edition=2018" )
42
83
. arg ( "--crate-name=thiserror" )
0 commit comments