22//! This script is responsible for generating the bindings to the PHP Zend API.
33//! It also checks the PHP version for compatibility with ext-php-rs and sets
44//! configuration flags accordingly.
5+ #![ allow( clippy:: inconsistent_digit_grouping) ]
56#[ cfg_attr( windows, path = "windows_build.rs" ) ]
67#[ cfg_attr( not( windows) , path = "unix_build.rs" ) ]
78mod impl_;
@@ -19,21 +20,25 @@ use anyhow::{anyhow, bail, Context, Result};
1920use bindgen:: RustTarget ;
2021use impl_:: Provider ;
2122
22- const MIN_PHP_API_VER : u32 = 20200930 ;
23- const MAX_PHP_API_VER : u32 = 20240924 ;
23+ const MIN_PHP_API_VER : u32 = 2020_09_30 ;
24+ const MAX_PHP_API_VER : u32 = 2024_09_24 ;
2425
2526/// Provides information about the PHP installation.
2627pub trait PHPProvider < ' a > : Sized {
2728 /// Create a new PHP provider.
29+ #[ allow( clippy:: missing_errors_doc) ]
2830 fn new ( info : & ' a PHPInfo ) -> Result < Self > ;
2931
3032 /// Retrieve a list of absolute include paths.
33+ #[ allow( clippy:: missing_errors_doc) ]
3134 fn get_includes ( & self ) -> Result < Vec < PathBuf > > ;
3235
3336 /// Retrieve a list of macro definitions to pass to the compiler.
37+ #[ allow( clippy:: missing_errors_doc) ]
3438 fn get_defines ( & self ) -> Result < Vec < ( & ' static str , & ' static str ) > > ;
3539
3640 /// Writes the bindings to a file.
41+ #[ allow( clippy:: missing_errors_doc) ]
3742 fn write_bindings ( & self , bindings : String , writer : & mut impl Write ) -> Result < ( ) > {
3843 for line in bindings. lines ( ) {
3944 writeln ! ( writer, "{line}" ) ?;
@@ -42,12 +47,14 @@ pub trait PHPProvider<'a>: Sized {
4247 }
4348
4449 /// Prints any extra link arguments.
50+ #[ allow( clippy:: missing_errors_doc) ]
4551 fn print_extra_link_args ( & self ) -> Result < ( ) > {
4652 Ok ( ( ) )
4753 }
4854}
4955
5056/// Finds the location of an executable `name`.
57+ #[ must_use]
5158pub fn find_executable ( name : & str ) -> Option < PathBuf > {
5259 const WHICH : & str = if cfg ! ( windows) { "where" } else { "which" } ;
5360 let cmd = Command :: new ( WHICH ) . arg ( name) . output ( ) . ok ( ) ?;
@@ -59,7 +66,7 @@ pub fn find_executable(name: &str) -> Option<PathBuf> {
5966 }
6067}
6168
62- /// Returns an environment variable's value as a PathBuf
69+ /// Returns an environment variable's value as a ` PathBuf`
6370pub fn path_from_env ( key : & str ) -> Option < PathBuf > {
6471 std:: env:: var_os ( key) . map ( PathBuf :: from)
6572}
@@ -85,6 +92,9 @@ pub struct PHPInfo(String);
8592
8693impl PHPInfo {
8794 /// Get the PHP info.
95+ ///
96+ /// # Errors
97+ /// - `php -i` command failed to execute successfully
8898 pub fn get ( php : & Path ) -> Result < Self > {
8999 let cmd = Command :: new ( php)
90100 . arg ( "-i" )
@@ -108,6 +118,9 @@ impl PHPInfo {
108118 }
109119
110120 /// Checks if thread safety is enabled.
121+ ///
122+ /// # Errors
123+ /// - `PHPInfo` does not contain thread satety information
111124 pub fn thread_safety ( & self ) -> Result < bool > {
112125 Ok ( self
113126 . get_key ( "Thread Safety" )
@@ -116,6 +129,9 @@ impl PHPInfo {
116129 }
117130
118131 /// Checks if PHP was built with debug.
132+ ///
133+ /// # Errors
134+ /// - `PHPInfo` does not contain debug build information
119135 pub fn debug ( & self ) -> Result < bool > {
120136 Ok ( self
121137 . get_key ( "Debug Build" )
@@ -124,12 +140,18 @@ impl PHPInfo {
124140 }
125141
126142 /// Get the php version.
143+ ///
144+ /// # Errors
145+ /// - `PHPInfo` does not contain version number
127146 pub fn version ( & self ) -> Result < & str > {
128147 self . get_key ( "PHP Version" )
129148 . context ( "Failed to get PHP version" )
130149 }
131150
132151 /// Get the zend version.
152+ ///
153+ /// # Errors
154+ /// - `PHPInfo` does not contain php api version
133155 pub fn zend_version ( & self ) -> Result < u32 > {
134156 self . get_key ( "PHP API" )
135157 . context ( "Failed to get Zend version" )
@@ -202,7 +224,7 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
202224 . layout_tests ( env:: var ( "EXT_PHP_RS_TEST" ) . is_ok ( ) )
203225 . rust_target ( RustTarget :: Nightly ) ;
204226
205- for binding in ALLOWED_BINDINGS . iter ( ) {
227+ for binding in ALLOWED_BINDINGS {
206228 bindgen = bindgen
207229 . allowlist_function ( binding)
208230 . allowlist_type ( binding)
@@ -230,6 +252,11 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
230252/// Checks the PHP Zend API version for compatibility with ext-php-rs, setting
231253/// any configuration flags required.
232254fn check_php_version ( info : & PHPInfo ) -> Result < ( ) > {
255+ const PHP_81_API_VER : u32 = 2021_09_02 ;
256+ const PHP_82_API_VER : u32 = 2022_08_29 ;
257+ const PHP_83_API_VER : u32 = 2023_08_31 ;
258+ const PHP_84_API_VER : u32 = 2024_09_24 ;
259+
233260 let version = info. zend_version ( ) ?;
234261
235262 if !( MIN_PHP_API_VER ..=MAX_PHP_API_VER ) . contains ( & version) {
@@ -245,14 +272,6 @@ fn check_php_version(info: &PHPInfo) -> Result<()> {
245272 //
246273 // The PHP version cfg flags should also stack - if you compile on PHP 8.2 you
247274 // should get both the `php81` and `php82` flags.
248- const PHP_81_API_VER : u32 = 20210902 ;
249-
250- const PHP_82_API_VER : u32 = 20220829 ;
251-
252- const PHP_83_API_VER : u32 = 20230831 ;
253-
254- const PHP_84_API_VER : u32 = 20240924 ;
255-
256275 println ! (
257276 "cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)"
258277 ) ;
0 commit comments