@@ -18,7 +18,6 @@ use std::{
18
18
19
19
use std:: { env, process:: Command , str:: FromStr } ;
20
20
21
- #[ cfg( feature = "resolve-config" ) ]
22
21
use once_cell:: sync:: OnceCell ;
23
22
24
23
pub use impl_:: {
@@ -135,17 +134,6 @@ fn resolve_cross_compile_config_path() -> Option<PathBuf> {
135
134
/// so this function is unstable.
136
135
#[ doc( hidden) ]
137
136
pub fn print_feature_cfgs ( ) {
138
- fn rustc_minor_version ( ) -> Option < u32 > {
139
- let rustc = env:: var_os ( "RUSTC" ) ?;
140
- let output = Command :: new ( rustc) . arg ( "--version" ) . output ( ) . ok ( ) ?;
141
- let version = core:: str:: from_utf8 ( & output. stdout ) . ok ( ) ?;
142
- let mut pieces = version. split ( '.' ) ;
143
- if pieces. next ( ) != Some ( "rustc 1" ) {
144
- return None ;
145
- }
146
- pieces. next ( ) ?. parse ( ) . ok ( )
147
- }
148
-
149
137
let rustc_minor_version = rustc_minor_version ( ) . unwrap_or ( 0 ) ;
150
138
151
139
// invalid_from_utf8 lint was added in Rust 1.74
@@ -160,6 +148,11 @@ pub fn print_feature_cfgs() {
160
148
/// - <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg>
161
149
#[ doc( hidden) ]
162
150
pub fn print_expected_cfgs ( ) {
151
+ if rustc_minor_version ( ) . map_or ( false , |version| version < 80 ) {
152
+ // rustc 1.80.0 stabilized `rustc-check-cfg` feature, don't emit before
153
+ return ;
154
+ }
155
+
163
156
println ! ( "cargo:rustc-check-cfg=cfg(Py_LIMITED_API)" ) ;
164
157
println ! ( "cargo:rustc-check-cfg=cfg(PyPy)" ) ;
165
158
println ! ( "cargo:rustc-check-cfg=cfg(GraalPy)" ) ;
@@ -233,6 +226,20 @@ pub mod pyo3_build_script_impl {
233
226
}
234
227
}
235
228
229
+ fn rustc_minor_version ( ) -> Option < u32 > {
230
+ static RUSTC_MINOR_VERSION : OnceCell < Option < u32 > > = OnceCell :: new ( ) ;
231
+ * RUSTC_MINOR_VERSION . get_or_init ( || {
232
+ let rustc = env:: var_os ( "RUSTC" ) ?;
233
+ let output = Command :: new ( rustc) . arg ( "--version" ) . output ( ) . ok ( ) ?;
234
+ let version = core:: str:: from_utf8 ( & output. stdout ) . ok ( ) ?;
235
+ let mut pieces = version. split ( '.' ) ;
236
+ if pieces. next ( ) != Some ( "rustc 1" ) {
237
+ return None ;
238
+ }
239
+ pieces. next ( ) ?. parse ( ) . ok ( )
240
+ } )
241
+ }
242
+
236
243
#[ cfg( test) ]
237
244
mod tests {
238
245
use super :: * ;
0 commit comments