@@ -35,6 +35,9 @@ pub trait PHPProvider<'a>: Sized {
3535 /// Retrieve a list of absolute include paths.
3636 fn get_includes ( & self ) -> Result < Vec < PathBuf > > ;
3737
38+ /// Retrieve a list of compiled sapis
39+ fn get_sapis ( & self ) -> Result < Vec < String > > ;
40+
3841 /// Retrieve a list of macro definitions to pass to the compiler.
3942 fn get_defines ( & self ) -> Result < Vec < ( & ' static str , & ' static str ) > > ;
4043
@@ -47,7 +50,7 @@ pub trait PHPProvider<'a>: Sized {
4750 }
4851
4952 /// Prints any extra link arguments.
50- fn print_extra_link_args ( & self ) -> Result < ( ) > {
53+ fn print_extra_link_args ( & self , _has_embed : bool ) -> Result < ( ) > {
5154 Ok ( ( ) )
5255 }
5356}
@@ -167,7 +170,6 @@ fn build_wrapper(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<()> {
167170 Ok ( ( ) )
168171}
169172
170- #[ cfg( feature = "embed" ) ]
171173/// Builds the embed library.
172174fn build_embed ( defines : & [ ( & str , & str ) ] , includes : & [ PathBuf ] ) -> Result < ( ) > {
173175 let mut build = cc:: Build :: new ( ) ;
@@ -186,12 +188,11 @@ fn build_embed(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<()> {
186188fn generate_bindings (
187189 defines : & [ ( & str , & str ) ] ,
188190 includes : & [ PathBuf ] ,
189- # [ allow ( unused ) ] info : & PHPInfo ,
191+ has_embed : bool ,
190192) -> Result < String > {
191193 let mut bindgen = bindgen:: Builder :: default ( ) ;
192194
193- #[ cfg( feature = "embed" ) ]
194- if !info. thread_safety ( ) ? || info. zend_version ( ) ? >= PHP_81_API_VER {
195+ if has_embed {
195196 bindgen = bindgen. header ( "src/embed/embed.h" ) ;
196197 }
197198
@@ -256,7 +257,7 @@ fn check_php_version(info: &PHPInfo) -> Result<()> {
256257 // should get both the `php81` and `php82` flags.
257258
258259 println ! (
259- "cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)"
260+ "cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, php_embed, docs)"
260261 ) ;
261262 println ! ( "cargo:rustc-cfg=php80" ) ;
262263
@@ -319,18 +320,21 @@ fn main() -> Result<()> {
319320 let info = PHPInfo :: get ( & php) ?;
320321 let provider = Provider :: new ( & info) ?;
321322
323+ let sapis = provider. get_sapis ( ) ?;
322324 let includes = provider. get_includes ( ) ?;
323325 let defines = provider. get_defines ( ) ?;
326+ let has_embed = sapis. contains ( & "embed" . to_string ( ) ) ;
324327
325328 check_php_version ( & info) ?;
326329 build_wrapper ( & defines, & includes) ?;
327330
328- #[ cfg( feature = "embed" ) ]
329- if !info. thread_safety ( ) ? || info. zend_version ( ) ? >= PHP_81_API_VER {
331+ if has_embed {
332+ println ! ( "cargo:rustc-cfg=php_embed" ) ;
333+
330334 build_embed ( & defines, & includes) ?;
331335 }
332336
333- let bindings = generate_bindings ( & defines, & includes, & info ) ?;
337+ let bindings = generate_bindings ( & defines, & includes, has_embed ) ?;
334338
335339 let out_file =
336340 File :: create ( & out_path) . context ( "Failed to open output bindings file for writing" ) ?;
@@ -343,7 +347,7 @@ fn main() -> Result<()> {
343347 if info. thread_safety ( ) ? {
344348 println ! ( "cargo:rustc-cfg=php_zts" ) ;
345349 }
346- provider. print_extra_link_args ( ) ?;
350+ provider. print_extra_link_args ( has_embed ) ?;
347351
348352 // Generate guide tests
349353 let test_md = skeptic:: markdown_files_of_directory ( "guide" ) ;
0 commit comments