2
2
//! This script is responsible for generating the bindings to the PHP Zend API.
3
3
//! It also checks the PHP version for compatibility with ext-php-rs and sets
4
4
//! configuration flags accordingly.
5
+ #![ allow( clippy:: inconsistent_digit_grouping) ]
5
6
#[ cfg_attr( windows, path = "windows_build.rs" ) ]
6
7
#[ cfg_attr( not( windows) , path = "unix_build.rs" ) ]
7
8
mod impl_;
@@ -19,21 +20,25 @@ use anyhow::{anyhow, bail, Context, Result};
19
20
use bindgen:: RustTarget ;
20
21
use impl_:: Provider ;
21
22
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 ;
24
25
25
26
/// Provides information about the PHP installation.
26
27
pub trait PHPProvider < ' a > : Sized {
27
28
/// Create a new PHP provider.
29
+ #[ allow( clippy:: missing_errors_doc) ]
28
30
fn new ( info : & ' a PHPInfo ) -> Result < Self > ;
29
31
30
32
/// Retrieve a list of absolute include paths.
33
+ #[ allow( clippy:: missing_errors_doc) ]
31
34
fn get_includes ( & self ) -> Result < Vec < PathBuf > > ;
32
35
33
36
/// Retrieve a list of macro definitions to pass to the compiler.
37
+ #[ allow( clippy:: missing_errors_doc) ]
34
38
fn get_defines ( & self ) -> Result < Vec < ( & ' static str , & ' static str ) > > ;
35
39
36
40
/// Writes the bindings to a file.
41
+ #[ allow( clippy:: missing_errors_doc) ]
37
42
fn write_bindings ( & self , bindings : String , writer : & mut impl Write ) -> Result < ( ) > {
38
43
for line in bindings. lines ( ) {
39
44
writeln ! ( writer, "{line}" ) ?;
@@ -42,12 +47,14 @@ pub trait PHPProvider<'a>: Sized {
42
47
}
43
48
44
49
/// Prints any extra link arguments.
50
+ #[ allow( clippy:: missing_errors_doc) ]
45
51
fn print_extra_link_args ( & self ) -> Result < ( ) > {
46
52
Ok ( ( ) )
47
53
}
48
54
}
49
55
50
56
/// Finds the location of an executable `name`.
57
+ #[ must_use]
51
58
pub fn find_executable ( name : & str ) -> Option < PathBuf > {
52
59
const WHICH : & str = if cfg ! ( windows) { "where" } else { "which" } ;
53
60
let cmd = Command :: new ( WHICH ) . arg ( name) . output ( ) . ok ( ) ?;
@@ -59,7 +66,7 @@ pub fn find_executable(name: &str) -> Option<PathBuf> {
59
66
}
60
67
}
61
68
62
- /// Returns an environment variable's value as a PathBuf
69
+ /// Returns an environment variable's value as a ` PathBuf`
63
70
pub fn path_from_env ( key : & str ) -> Option < PathBuf > {
64
71
std:: env:: var_os ( key) . map ( PathBuf :: from)
65
72
}
@@ -85,6 +92,9 @@ pub struct PHPInfo(String);
85
92
86
93
impl PHPInfo {
87
94
/// Get the PHP info.
95
+ ///
96
+ /// # Errors
97
+ /// - `php -i` command failed to execute successfully
88
98
pub fn get ( php : & Path ) -> Result < Self > {
89
99
let cmd = Command :: new ( php)
90
100
. arg ( "-i" )
@@ -108,6 +118,9 @@ impl PHPInfo {
108
118
}
109
119
110
120
/// Checks if thread safety is enabled.
121
+ ///
122
+ /// # Errors
123
+ /// - `PHPInfo` does not contain thread satety information
111
124
pub fn thread_safety ( & self ) -> Result < bool > {
112
125
Ok ( self
113
126
. get_key ( "Thread Safety" )
@@ -116,6 +129,9 @@ impl PHPInfo {
116
129
}
117
130
118
131
/// Checks if PHP was built with debug.
132
+ ///
133
+ /// # Errors
134
+ /// - `PHPInfo` does not contain debug build information
119
135
pub fn debug ( & self ) -> Result < bool > {
120
136
Ok ( self
121
137
. get_key ( "Debug Build" )
@@ -124,12 +140,18 @@ impl PHPInfo {
124
140
}
125
141
126
142
/// Get the php version.
143
+ ///
144
+ /// # Errors
145
+ /// - `PHPInfo` does not contain version number
127
146
pub fn version ( & self ) -> Result < & str > {
128
147
self . get_key ( "PHP Version" )
129
148
. context ( "Failed to get PHP version" )
130
149
}
131
150
132
151
/// Get the zend version.
152
+ ///
153
+ /// # Errors
154
+ /// - `PHPInfo` does not contain php api version
133
155
pub fn zend_version ( & self ) -> Result < u32 > {
134
156
self . get_key ( "PHP API" )
135
157
. context ( "Failed to get Zend version" )
@@ -202,7 +224,7 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
202
224
. layout_tests ( env:: var ( "EXT_PHP_RS_TEST" ) . is_ok ( ) )
203
225
. rust_target ( RustTarget :: Nightly ) ;
204
226
205
- for binding in ALLOWED_BINDINGS . iter ( ) {
227
+ for binding in ALLOWED_BINDINGS {
206
228
bindgen = bindgen
207
229
. allowlist_function ( binding)
208
230
. allowlist_type ( binding)
@@ -230,6 +252,11 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
230
252
/// Checks the PHP Zend API version for compatibility with ext-php-rs, setting
231
253
/// any configuration flags required.
232
254
fn 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
+
233
260
let version = info. zend_version ( ) ?;
234
261
235
262
if !( MIN_PHP_API_VER ..=MAX_PHP_API_VER ) . contains ( & version) {
@@ -245,14 +272,6 @@ fn check_php_version(info: &PHPInfo) -> Result<()> {
245
272
//
246
273
// The PHP version cfg flags should also stack - if you compile on PHP 8.2 you
247
274
// 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
-
256
275
println ! (
257
276
"cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)"
258
277
) ;
0 commit comments