@@ -23,54 +23,75 @@ macro_rules! die {
2323fn main ( ) {
2424 println ! ( "cargo:rustc-check-cfg=cfg(build_feature_probe)" ) ;
2525 println ! ( "cargo:rustc-check-cfg=cfg(bool_to_result)" ) ;
26- println ! ( "cargo:rerun-if-changed=src/nightly.rs" ) ;
27-
28- let bool_to_result;
29- let consider_rustc_bootstrap;
30- if compile_probe ( false ) {
31- // This is a nightly or dev compiler, so it supports unstable
32- // features regardless of RUSTC_BOOTSTRAP. No need to rerun build
33- // script if RUSTC_BOOTSTRAP is changed.
34- bool_to_result = true ;
35- consider_rustc_bootstrap = false ;
36- } else if let Some ( rustc_bootstrap) = std:: env:: var_os ( "RUSTC_BOOTSTRAP" ) {
37- if compile_probe ( true ) {
38- // This is a stable or beta compiler for which the user has set
39- // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build
40- // script if they change it.
41- bool_to_result = true ;
42- consider_rustc_bootstrap = true ;
43- } else if rustc_bootstrap == "1" {
44- // This compiler does not support the generic member access API
45- // in the form that anyhow expects. No need to pay attention to
46- // RUSTC_BOOTSTRAP.
47- bool_to_result = false ;
48- consider_rustc_bootstrap = false ;
49- } else {
50- // This is a stable or beta compiler for which RUSTC_BOOTSTRAP
51- // is set to restrict the use of unstable features by this
52- // crate.
53- bool_to_result = false ;
54- consider_rustc_bootstrap = true ;
55- }
56- } else {
57- // Without RUSTC_BOOTSTRAP, this compiler does not support the
58- // unstable features this crate uses, but try again if the user turns on
59- // unstable features.
60- bool_to_result = false ;
61- consider_rustc_bootstrap = true ;
62- }
26+ println ! ( "cargo:rustc-check-cfg=cfg(windows_process_exit_code_from)" ) ;
27+ println ! ( "cargo:rerun-if-changed=src/nightly/mod.rs" ) ;
28+ println ! ( "cargo:rerun-if-changed=src/nightly/bool_or.rs" ) ;
29+ println ! ( "cargo:rerun-if-changed=src/nightly/windows_process_exit_code.rs" ) ;
30+
31+ let CompilerProbeResult {
32+ supported : bool_to_result,
33+ consider_rustc_bootstrap,
34+ } = compiler_probe ( "bool_or.rs" ) ;
6335
6436 if bool_to_result {
6537 println ! ( "cargo:rustc-cfg=bool_to_result" ) ;
6638 }
6739
40+ #[ cfg( windows) ]
41+ let consider_rustc_bootstrap = {
42+ let CompilerProbeResult {
43+ supported,
44+ consider_rustc_bootstrap : consider_rustc_bootstrap_windows,
45+ } = compiler_probe ( "windows_process_exit_code.rs" ) ;
46+ if supported {
47+ println ! ( "cargo:rustc-cfg=windows_process_exit_code_from" ) ;
48+ }
49+
50+ consider_rustc_bootstrap || consider_rustc_bootstrap_windows
51+ } ;
52+
6853 if consider_rustc_bootstrap {
6954 println ! ( "cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP" ) ;
7055 }
7156}
7257
73- fn compile_probe ( rustc_bootstrap : bool ) -> bool {
58+ struct CompilerProbeResult {
59+ supported : bool ,
60+ consider_rustc_bootstrap : bool ,
61+ }
62+
63+ fn compiler_probe ( filename : impl AsRef < Path > ) -> CompilerProbeResult {
64+ if compile_probe ( & filename, false ) {
65+ CompilerProbeResult {
66+ supported : true ,
67+ consider_rustc_bootstrap : false ,
68+ }
69+ } else if let Some ( rustc_bootstrap) = std:: env:: var_os ( "RUSTC_BOOTSTRAP" ) {
70+ if compile_probe ( "bool_or.rs" , true ) {
71+ CompilerProbeResult {
72+ supported : true ,
73+ consider_rustc_bootstrap : true ,
74+ }
75+ } else if rustc_bootstrap == "1" {
76+ CompilerProbeResult {
77+ supported : false ,
78+ consider_rustc_bootstrap : false ,
79+ }
80+ } else {
81+ CompilerProbeResult {
82+ supported : false ,
83+ consider_rustc_bootstrap : true ,
84+ }
85+ }
86+ } else {
87+ CompilerProbeResult {
88+ supported : false ,
89+ consider_rustc_bootstrap : true ,
90+ }
91+ }
92+ }
93+
94+ fn compile_probe ( filename : impl AsRef < Path > , rustc_bootstrap : bool ) -> bool {
7495 if std:: env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) {
7596 println ! ( "cargo:rerun-if-env-changed=RUSTC_STAGE" ) ;
7697 // We are running inside rustc bootstrap. This is a highly non-standard
@@ -89,7 +110,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
89110 let out_subdir = Path :: new ( & out_dir) . join ( probe_dir) ;
90111 mkdir ( & out_subdir) ;
91112
92- let probefile = Path :: new ( "src" ) . join ( "nightly.rs" ) ;
113+ let probefile = Path :: new ( "src" ) . join ( "nightly" ) . join ( filename ) ;
93114
94115 let mut cmd = rustc_command ( ) ;
95116
0 commit comments