@@ -55,8 +55,7 @@ fn main() {
5555
5656 cfg_php_major_version ( vernum) ;
5757 cfg_php_feature_flags ( vernum) ;
58- cfg_zts ( ) ;
59- cfg_php_debug ( ) ;
58+ cfg_php_build ( ) ;
6059 apple_linker_flags ( ) ;
6160}
6261
@@ -407,8 +406,9 @@ fn cfg_php_feature_flags(vernum: u64) {
407406 }
408407}
409408
410- fn cfg_zts ( ) {
409+ fn cfg_php_build ( ) {
411410 println ! ( "cargo::rustc-check-cfg=cfg(php_zts)" ) ;
411+ println ! ( "cargo::rustc-check-cfg=cfg(php_debug)" ) ;
412412
413413 let output = Command :: new ( "php-config" )
414414 . arg ( "--include-dir" )
@@ -426,9 +426,8 @@ fn cfg_zts() {
426426 . expect ( "`php-config`'s stdout to be valid utf8" )
427427 . trim ( ) ;
428428
429- // Create a temporary C file to probe ZTS
430429 let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
431- let probe_path = Path :: new ( & out_dir) . join ( "zts_probe .c" ) ;
430+ let probe_path = Path :: new ( & out_dir) . join ( "php_build_probe .c" ) ;
432431 fs:: write (
433432 & probe_path,
434433 r#"
@@ -440,70 +439,6 @@ int main() {
440439#else
441440 printf("0");
442441#endif
443- return 0;
444- }
445- "# ,
446- )
447- . expect ( "Failed to write ZTS probe file" ) ;
448-
449- // Get the C compiler from cc crate
450- let compiler = cc:: Build :: new ( ) . get_compiler ( ) ;
451-
452- // Compile the probe to an executable
453- let probe_exe = Path :: new ( & out_dir) . join ( "zts_probe" ) ;
454- let compile_status = Command :: new ( compiler. path ( ) )
455- . arg ( format ! ( "-I{}" , include_dir) )
456- . arg ( & probe_path)
457- . arg ( "-o" )
458- . arg ( & probe_exe)
459- . status ( )
460- . expect ( "Failed to compile ZTS probe" ) ;
461-
462- if !compile_status. success ( ) {
463- panic ! ( "Failed to compile ZTS probe" ) ;
464- }
465-
466- // Run the probe
467- let probe_output = Command :: new ( & probe_exe)
468- . output ( )
469- . expect ( "Failed to run ZTS probe" ) ;
470-
471- let zts_value = std:: str:: from_utf8 ( & probe_output. stdout )
472- . expect ( "ZTS probe output not UTF-8" )
473- . trim ( ) ;
474-
475- if zts_value == "1" {
476- println ! ( "cargo:rustc-cfg=php_zts" ) ;
477- }
478- }
479-
480- fn cfg_php_debug ( ) {
481- println ! ( "cargo::rustc-check-cfg=cfg(php_debug)" ) ;
482-
483- let output = Command :: new ( "php-config" )
484- . arg ( "--include-dir" )
485- . output ( )
486- . expect ( "Unable to run `php-config`. Is it in your PATH?" ) ;
487-
488- if !output. status . success ( ) {
489- match String :: from_utf8 ( output. stderr ) {
490- Ok ( stderr) => panic ! ( "`php-config --include-dir` failed: {stderr}" ) ,
491- Err ( err) => panic ! ( "`php-config --include-dir` failed, not utf8: {err}" ) ,
492- }
493- }
494-
495- let include_dir = std:: str:: from_utf8 ( output. stdout . as_slice ( ) )
496- . expect ( "`php-config`'s stdout to be valid utf8" )
497- . trim ( ) ;
498-
499- let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
500- let probe_path = Path :: new ( & out_dir) . join ( "php_debug_probe.c" ) ;
501- fs:: write (
502- & probe_path,
503- r#"
504- #include "main/php_config.h"
505- #include <stdio.h>
506- int main() {
507442#if ZEND_DEBUG
508443 printf("1");
509444#else
@@ -513,31 +448,41 @@ int main() {
513448}
514449"# ,
515450 )
516- . expect ( "Failed to write PHP debug probe file" ) ;
451+ . expect ( "Failed to write PHP build probe file" ) ;
517452
518453 let compiler = cc:: Build :: new ( ) . get_compiler ( ) ;
519- let probe_exe = Path :: new ( & out_dir) . join ( "php_debug_probe " ) ;
454+ let probe_exe = Path :: new ( & out_dir) . join ( "php_build_probe " ) ;
520455 let compile_status = Command :: new ( compiler. path ( ) )
521456 . arg ( format ! ( "-I{}" , include_dir) )
522457 . arg ( & probe_path)
523458 . arg ( "-o" )
524459 . arg ( & probe_exe)
525460 . status ( )
526- . expect ( "Failed to compile PHP debug probe" ) ;
461+ . expect ( "Failed to compile PHP build probe" ) ;
527462
528463 if !compile_status. success ( ) {
529- panic ! ( "Failed to compile PHP debug probe" ) ;
464+ panic ! ( "Failed to compile PHP build probe" ) ;
530465 }
531466
532467 let probe_output = Command :: new ( & probe_exe)
533468 . output ( )
534- . expect ( "Failed to run PHP debug probe" ) ;
469+ . expect ( "Failed to run PHP build probe" ) ;
535470
536- let debug_value = std:: str:: from_utf8 ( & probe_output. stdout )
537- . expect ( "PHP debug probe output not UTF-8" )
471+ let probe_value = std:: str:: from_utf8 ( & probe_output. stdout )
472+ . expect ( "PHP build probe output not UTF-8" )
538473 . trim ( ) ;
474+ let ( zts, debug) = match probe_value {
475+ "00" => ( false , false ) ,
476+ "01" => ( false , true ) ,
477+ "10" => ( true , false ) ,
478+ "11" => ( true , true ) ,
479+ _ => panic ! ( "Unexpected PHP build probe output: {probe_value:?}" ) ,
480+ } ;
539481
540- if debug_value == "1" {
482+ if zts {
483+ println ! ( "cargo:rustc-cfg=php_zts" ) ;
484+ }
485+ if debug {
541486 println ! ( "cargo:rustc-cfg=php_debug" ) ;
542487 }
543488}
0 commit comments