1
1
use bindgen:: callbacks:: IntKind ;
2
+ use rustc_version:: version_meta;
2
3
use std:: collections:: HashSet ;
3
4
use std:: path:: Path ;
4
5
use std:: path:: PathBuf ;
@@ -13,7 +14,7 @@ fn main() {
13
14
14
15
if !php_config_includes_output. status . success ( ) {
15
16
match String :: from_utf8 ( php_config_includes_output. stderr ) {
16
- Ok ( stderr) => panic ! ( "`php-config failed: {}" , stderr ) ,
17
+ Ok ( stderr) => panic ! ( "`php-config failed: {stderr}" ) ,
17
18
Err ( err) => panic ! (
18
19
"`php-config` failed, not utf8: {}" ,
19
20
String :: from_utf8_lossy( err. as_bytes( ) )
@@ -26,7 +27,7 @@ fn main() {
26
27
. expect ( "Failed to read VERSION file" )
27
28
. trim ( )
28
29
. to_string ( ) ;
29
- println ! ( "cargo:rustc-env=PROFILER_VERSION={}" , version ) ;
30
+ println ! ( "cargo:rustc-env=PROFILER_VERSION={version}" ) ;
30
31
println ! ( "cargo:rerun-if-changed=../VERSION" ) ;
31
32
32
33
let php_config_includes = std:: str:: from_utf8 ( php_config_includes_output. stdout . as_slice ( ) )
@@ -65,7 +66,7 @@ fn php_config_vernum() -> u64 {
65
66
66
67
if !output. status . success ( ) {
67
68
match String :: from_utf8 ( output. stderr ) {
68
- Ok ( stderr) => panic ! ( "`php-config --vernum` failed: {}" , stderr ) ,
69
+ Ok ( stderr) => panic ! ( "`php-config --vernum` failed: {stderr}" ) ,
69
70
Err ( err) => panic ! (
70
71
"`php-config --vernum` failed, not utf8: {}" ,
71
72
String :: from_utf8_lossy( err. as_bytes( ) )
@@ -134,7 +135,7 @@ fn build_zend_php_ffis(
134
135
] ;
135
136
136
137
for file in zai_c_files. iter ( ) . chain ( ZAI_H_FILES . iter ( ) ) {
137
- println ! ( "cargo:rerun-if-changed={}" , * file ) ;
138
+ println ! ( "cargo:rerun-if-changed={file}" ) ;
138
139
}
139
140
140
141
let output = Command :: new ( "php-config" )
@@ -143,7 +144,10 @@ fn build_zend_php_ffis(
143
144
. expect ( "Unable to run `php-config`. Is it in your PATH?" ) ;
144
145
145
146
let prefix = String :: from_utf8 ( output. stdout ) . expect ( "only utf8 chars work" ) ;
146
- println ! ( "cargo:rustc-link-search=native={}/lib" , prefix. trim( ) ) ;
147
+ println ! (
148
+ "cargo:rustc-link-search=native={prefix}/lib" ,
149
+ prefix = prefix. trim( )
150
+ ) ;
147
151
148
152
let files = [ "src/php_ffi.c" , "../ext/handlers_api.c" ] ;
149
153
let post_startup_cb = if post_startup_cb { "1" } else { "0" } ;
@@ -296,7 +300,18 @@ fn generate_bindings(php_config_includes: &str, fibers: bool, zend_error_observe
296
300
. expect ( "bindings to be written successfully" ) ;
297
301
}
298
302
303
+ // See https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html
304
+ // We can remove this when we're on Rust 1.80+.
305
+ fn has_check_cfg ( ) -> bool {
306
+ let meta = version_meta ( ) . unwrap ( ) ;
307
+ assert_eq ! ( 1 , meta. semver. major) ;
308
+ meta. semver . minor >= 80
309
+ }
310
+
299
311
fn cfg_post_startup_cb ( vernum : u64 ) -> bool {
312
+ if has_check_cfg ( ) {
313
+ println ! ( "cargo::rustc-check-cfg=cfg(php_post_startup_cb)" ) ;
314
+ }
300
315
if vernum >= 70300 {
301
316
println ! ( "cargo:rustc-cfg=php_post_startup_cb" ) ;
302
317
true
@@ -306,6 +321,9 @@ fn cfg_post_startup_cb(vernum: u64) -> bool {
306
321
}
307
322
308
323
fn cfg_preload ( vernum : u64 ) -> bool {
324
+ if has_check_cfg ( ) {
325
+ println ! ( "cargo::rustc-check-cfg=cfg(php_preload)" ) ;
326
+ }
309
327
if vernum >= 70400 {
310
328
println ! ( "cargo:rustc-cfg=php_preload" ) ;
311
329
true
@@ -315,6 +333,9 @@ fn cfg_preload(vernum: u64) -> bool {
315
333
}
316
334
317
335
fn cfg_run_time_cache ( vernum : u64 ) -> bool {
336
+ if has_check_cfg ( ) {
337
+ println ! ( "cargo::rustc-check-cfg=cfg(php_run_time_cache)" ) ;
338
+ }
318
339
if vernum >= 80000 {
319
340
println ! ( "cargo:rustc-cfg=php_run_time_cache" ) ;
320
341
true
@@ -328,6 +349,9 @@ fn cfg_trigger_time_sample() -> bool {
328
349
}
329
350
330
351
fn cfg_zend_error_observer ( vernum : u64 ) -> bool {
352
+ if has_check_cfg ( ) {
353
+ println ! ( "cargo::rustc-check-cfg=cfg(zend_error_observer, zend_error_observer_80)" ) ;
354
+ }
331
355
if vernum >= 80000 {
332
356
println ! ( "cargo:rustc-cfg=zend_error_observer" ) ;
333
357
if vernum < 80100 {
@@ -340,6 +364,10 @@ fn cfg_zend_error_observer(vernum: u64) -> bool {
340
364
}
341
365
342
366
fn cfg_php_major_version ( vernum : u64 ) {
367
+ if has_check_cfg ( ) {
368
+ println ! ( "cargo::rustc-check-cfg=cfg(php7, php8)" ) ;
369
+ }
370
+
343
371
let major_version = match vernum {
344
372
70000 ..=79999 => 7 ,
345
373
80000 ..=89999 => 8 ,
@@ -354,6 +382,9 @@ fn cfg_php_major_version(vernum: u64) {
354
382
}
355
383
356
384
fn cfg_fibers ( vernum : u64 ) -> bool {
385
+ if has_check_cfg ( ) {
386
+ println ! ( "cargo::rustc-check-cfg=cfg(php_has_fibers)" ) ;
387
+ }
357
388
if vernum >= 80100 {
358
389
println ! ( "cargo:rustc-cfg=php_has_fibers" ) ;
359
390
true
@@ -363,6 +394,10 @@ fn cfg_fibers(vernum: u64) -> bool {
363
394
}
364
395
365
396
fn cfg_php_feature_flags ( vernum : u64 ) {
397
+ if has_check_cfg ( ) {
398
+ println ! ( "cargo::rustc-check-cfg=cfg(php_gc_status, php_zend_compile_string_has_position, php_gc_status_extended, php_frameless, php_opcache_restart_hook, php_zend_mm_set_custom_handlers_ex)" ) ;
399
+ }
400
+
366
401
if vernum >= 70300 {
367
402
println ! ( "cargo:rustc-cfg=php_gc_status" ) ;
368
403
}
@@ -380,6 +415,10 @@ fn cfg_php_feature_flags(vernum: u64) {
380
415
}
381
416
382
417
fn cfg_zts ( ) {
418
+ if has_check_cfg ( ) {
419
+ println ! ( "cargo::rustc-check-cfg=cfg(php_zts)" ) ;
420
+ }
421
+
383
422
let output = Command :: new ( "php" )
384
423
. arg ( "-n" )
385
424
. arg ( "-r" )
@@ -389,8 +428,8 @@ fn cfg_zts() {
389
428
390
429
if !output. status . success ( ) {
391
430
match String :: from_utf8 ( output. stderr ) {
392
- Ok ( stderr) => panic ! ( "`php failed: {}" , stderr ) ,
393
- Err ( err) => panic ! ( "`php` failed, not utf8: {}" , err ) ,
431
+ Ok ( stderr) => panic ! ( "`php failed: {stderr}" ) ,
432
+ Err ( err) => panic ! ( "`php` failed, not utf8: {err}" ) ,
394
433
}
395
434
}
396
435
0 commit comments