@@ -20,6 +20,7 @@ fn main() {
20
20
println ! ( "cargo:rustc-check-cfg=cfg(no_literal_c_string)" ) ;
21
21
println ! ( "cargo:rustc-check-cfg=cfg(no_source_text)" ) ;
22
22
println ! ( "cargo:rustc-check-cfg=cfg(proc_macro_span)" ) ;
23
+ println ! ( "cargo:rustc-check-cfg=cfg(proc_macro_span_location)" ) ;
23
24
println ! ( "cargo:rustc-check-cfg=cfg(procmacro2_backtrace)" ) ;
24
25
println ! ( "cargo:rustc-check-cfg=cfg(procmacro2_build_probe)" ) ;
25
26
println ! ( "cargo:rustc-check-cfg=cfg(procmacro2_nightly_testing)" ) ;
@@ -68,18 +69,16 @@ fn main() {
68
69
return ;
69
70
}
70
71
71
- println ! ( "cargo:rerun-if-changed=src/probe/proc_macro_span.rs" ) ;
72
-
73
72
let proc_macro_span;
74
73
let consider_rustc_bootstrap;
75
- if compile_probe ( false ) {
74
+ if compile_probe_unstable ( "proc_macro_span" , false ) {
76
75
// This is a nightly or dev compiler, so it supports unstable features
77
76
// regardless of RUSTC_BOOTSTRAP. No need to rerun build script if
78
77
// RUSTC_BOOTSTRAP is changed.
79
78
proc_macro_span = true ;
80
79
consider_rustc_bootstrap = false ;
81
80
} else if let Some ( rustc_bootstrap) = env:: var_os ( "RUSTC_BOOTSTRAP" ) {
82
- if compile_probe ( true ) {
81
+ if compile_probe_unstable ( "proc_macro_span" , true ) {
83
82
// This is a stable or beta compiler for which the user has set
84
83
// RUSTC_BOOTSTRAP to turn on unstable features. Rerun build script
85
84
// if they change it.
@@ -116,13 +115,19 @@ fn main() {
116
115
}
117
116
118
117
if proc_macro_span {
119
- // Enable non-dummy behavior of Span::start and Span::end methods which
120
- // requires an unstable compiler feature. Enabled when building with
121
- // nightly, unless `-Z allow-feature` in RUSTFLAGS disallows unstable
122
- // features.
118
+ // Enable non-dummy behavior of Span::byte_range and Span::join methods
119
+ // which requires an unstable compiler feature. Enabled when building
120
+ // with nightly, unless `-Z allow-feature` in RUSTFLAGS disallows
121
+ // unstable features.
123
122
println ! ( "cargo:rustc-cfg=proc_macro_span" ) ;
124
123
}
125
124
125
+ if proc_macro_span || ( rustc >= 88 && compile_probe_stable ( "proc_macro_span_location" ) ) {
126
+ // Enable non-dummy behavior of Span::start and Span::end methods on
127
+ // Rust 1.88+.
128
+ println ! ( "cargo:rustc-cfg=proc_macro_span_location" ) ;
129
+ }
130
+
126
131
if semver_exempt && proc_macro_span {
127
132
// Implement the semver exempt API in terms of the nightly-only
128
133
// proc_macro API.
@@ -134,22 +139,31 @@ fn main() {
134
139
}
135
140
}
136
141
137
- fn compile_probe ( rustc_bootstrap : bool ) -> bool {
138
- if env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) {
139
- // We are running inside rustc bootstrap. This is a highly non-standard
140
- // environment with issues such as:
141
- //
142
- // https://github.com/rust-lang/cargo/issues/11138
143
- // https://github.com/rust-lang/rust/issues/114839
144
- //
145
- // Let's just not use nightly features here.
146
- return false ;
147
- }
142
+ fn compile_probe_unstable ( feature : & str , rustc_bootstrap : bool ) -> bool {
143
+ // RUSTC_STAGE indicates that this crate is being compiled as a dependency
144
+ // of a multistage rustc bootstrap. This environment uses Cargo in a highly
145
+ // non-standard way with issues such as:
146
+ //
147
+ // https://github.com/rust-lang/cargo/issues/11138
148
+ // https://github.com/rust-lang/rust/issues/114839
149
+ //
150
+ env:: var_os ( "RUSTC_STAGE" ) . is_none ( ) && do_compile_probe ( feature, rustc_bootstrap)
151
+ }
152
+
153
+ fn compile_probe_stable ( feature : & str ) -> bool {
154
+ env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) || do_compile_probe ( feature, true )
155
+ }
156
+
157
+ fn do_compile_probe ( feature : & str , rustc_bootstrap : bool ) -> bool {
158
+ println ! ( "cargo:rerun-if-changed=src/probe/{}.rs" , feature) ;
148
159
149
160
let rustc = cargo_env_var ( "RUSTC" ) ;
150
161
let out_dir = cargo_env_var ( "OUT_DIR" ) ;
151
162
let out_subdir = Path :: new ( & out_dir) . join ( "probe" ) ;
152
- let probefile = Path :: new ( "src" ) . join ( "probe" ) . join ( "proc_macro_span.rs" ) ;
163
+ let probefile = Path :: new ( "src" )
164
+ . join ( "probe" )
165
+ . join ( feature)
166
+ . with_extension ( "rs" ) ;
153
167
154
168
if let Err ( err) = fs:: create_dir ( & out_subdir) {
155
169
if err. kind ( ) != ErrorKind :: AlreadyExists {
0 commit comments