Skip to content

Commit a2d21a4

Browse files
committed
feat(embed): remove embed as feature, detect it with php info
1 parent 9c27c64 commit a2d21a4

File tree

13 files changed

+41
-27
lines changed

13 files changed

+41
-27
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ jobs:
9090
# ext-php-rs requires nightly Rust when on Windows.
9191
- os: windows-latest
9292
rust: stable
93-
# setup-php doesn't support thread safe PHP on macOS with embed
94-
- os: macos-latest
95-
phpts: ts
9693
- os: macos-latest
9794
clang: "17"
9895
- os: ubuntu-latest

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ zip = "2.2"
3838

3939
[features]
4040
closure = []
41-
embed = []
4241

4342
[workspace]
4443
members = [

build.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
172174
fn 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<()> {
186188
fn 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");

src/builders/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
mod class;
55
mod function;
66
mod module;
7-
#[cfg(all(feature = "embed", any(php81, not(php_zts))))]
7+
#[cfg(php_embed)]
88
mod sapi;
99

1010
pub use class::ClassBuilder;
1111
pub use function::FunctionBuilder;
1212
pub use module::{ModuleBuilder, ModuleStartup};
13-
#[cfg(all(feature = "embed", any(php81, not(php_zts))))]
13+
#[cfg(php_embed)]
1414
pub use sapi::SapiBuilder;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub mod class;
2525
pub mod closure;
2626
pub mod constant;
2727
pub mod describe;
28-
#[cfg(all(feature = "embed", any(php81, not(php_zts))))]
28+
#[cfg(php_embed)]
2929
pub mod embed;
3030
#[doc(hidden)]
3131
pub mod internal;

src/types/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a> FromZvalMut<'a> for &'a mut ZendIterator {
183183
}
184184

185185
#[cfg(test)]
186-
#[cfg(all(feature = "embed", any(php81, not(php_zts))))]
186+
#[cfg(php_embed)]
187187
mod tests {
188188
use crate::embed::Embed;
189189

src/types/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'a> FromZval<'a> for &'a str {
456456
}
457457

458458
#[cfg(test)]
459-
#[cfg(all(feature = "embed", any(php81, not(php_zts))))]
459+
#[cfg(php_embed)]
460460
mod tests {
461461
use crate::embed::Embed;
462462

src/zend/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub use ini_entry_def::IniEntryDef;
3434
pub use linked_list::ZendLinkedList;
3535
pub use module::ModuleEntry;
3636
pub use streams::*;
37-
#[cfg(all(feature = "embed", any(php81, not(php_zts))))]
37+
#[cfg(php_embed)]
3838
pub(crate) use try_catch::panic_wrapper;
3939
pub use try_catch::{bailout, try_catch, try_catch_first};
4040

src/zend/try_catch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub unsafe fn bailout() -> ! {
102102
ext_php_rs_zend_bailout();
103103
}
104104

105-
#[cfg(all(feature = "embed", any(php81, not(php_zts))))]
105+
#[cfg(php_embed)]
106106
#[cfg(test)]
107107
mod tests {
108108
use crate::embed::Embed;

tests/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg_attr(windows, feature(abi_vectorcall))]
2-
#![cfg(all(feature = "embed", any(php81, not(php_zts))))]
2+
#![cfg(php_embed)]
33

44
extern crate ext_php_rs;
55

0 commit comments

Comments
 (0)