Skip to content

feat(enum): add basic enum support #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
env:
DOCS_RS: ""
run: cargo clean && cargo build

build:
name: Build and Test
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -161,12 +162,12 @@ jobs:
- name: Build
env:
EXT_PHP_RS_TEST: ""
run: cargo build --release --features closure,anyhow --all
run: cargo build --release --features closure,anyhow --workspace ${{ matrix.php == '8.0' && '--no-default-features' || '' }}
# Test
- name: Test inline examples
# Macos fails on unstable rust. We skip the inline examples test for now.
if: "!(contains(matrix.os, 'macos') && matrix.rust == 'nightly')"
run: cargo test --release --all --features closure,anyhow --no-fail-fast
run: cargo test --release --workspace --features closure,anyhow --no-fail-fast ${{ matrix.php == '8.0' && '--no-default-features' || '' }}
build-zts:
name: Build with ZTS
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: coverage
on:
push:
branches-ignore:
- 'release-plz-*'
- "release-plz-*"
pull_request:
branches-ignore:
- 'release-plz-*'
- "release-plz-*"
env:
# increment this manually to force cache eviction
RUST_CACHE_PREFIX: "v0-rust"
Expand Down Expand Up @@ -63,6 +63,6 @@ jobs:
cargo tarpaulin --version
- name: Run tests
run: |
cargo tarpaulin --engine llvm --workspace --all-features --tests --exclude tests --exclude-files docsrs_bindings.rs --timeout 120 --out Xml
cargo tarpaulin --engine llvm --workspace --all-features --tests --exclude tests --exclude-files docsrs_bindings.rs --exclude-files "crates/macros/tests/expand/*.expanded.rs" --timeout 120 --out Xml
- name: Upload coverage
uses: coverallsapp/github-action@v2
10 changes: 5 additions & 5 deletions .lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pre-commit:
The `docsrs_bindings.rs` file seems to be out of date.
Please check the updated bindings in `docsrs_bindings.rs` and commit the changes.
- name: "macro docs"
run: tools/update_lib_docs.sh && git diff --exit-code crates/macros/src/lib.rs
glob: "guide/src/macros/*.md"
fail_text: |
The macro crates documentation seems to be out of date.
Please check the updated documentation in `crates/macros/src/lib.rs` and commit the changes.
run: tools/update_lib_docs.sh
glob:
- "guide/src/macros/*.md"
- "crates/macros/src/lib.rs"
stage_fixed: true
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ native-tls = "0.2"
zip = "4.0"

[features]
default = ["enum"]
closure = []
embed = []
anyhow = ["dep:anyhow"]
enum = []

[workspace]
members = [
Expand Down
5 changes: 5 additions & 0 deletions allowed_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ bind! {
zend_declare_class_constant,
zend_declare_property,
zend_do_implement_interface,
zend_enum_add_case,
zend_enum_get_case,
zend_enum_new,
zend_execute_data,
zend_function_entry,
zend_hash_clean,
Expand Down Expand Up @@ -114,6 +117,7 @@ bind! {
zend_register_bool_constant,
zend_register_double_constant,
zend_register_ini_entries,
zend_register_internal_enum,
zend_ini_entry_def,
zend_register_internal_class_ex,
zend_register_long_constant,
Expand Down Expand Up @@ -191,6 +195,7 @@ bind! {
ZEND_ACC_DEPRECATED,
ZEND_ACC_DONE_PASS_TWO,
ZEND_ACC_EARLY_BINDING,
ZEND_ACC_ENUM,
ZEND_ACC_FAKE_CLOSURE,
ZEND_ACC_FINAL,
ZEND_ACC_GENERATOR,
Expand Down
13 changes: 10 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
Ok(bindings)
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
enum ApiVersion {
Php80 = 2020_09_30,
Php81 = 2021_09_02,
Expand All @@ -272,8 +272,15 @@ enum ApiVersion {

impl ApiVersion {
/// Returns the minimum API version supported by ext-php-rs.
pub const fn min() -> Self {
ApiVersion::Php80
pub fn min() -> Self {
[
ApiVersion::Php80,
#[cfg(feature = "enum")]
ApiVersion::Php81,
]
.into_iter()
.max()
.unwrap_or(Self::max())
}

/// Returns the maximum API version supported by ext-php-rs.
Expand Down
6 changes: 5 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"
categories = ["api-bindings", "command-line-interface"]

[dependencies]
ext-php-rs = { version = "0.14", path = "../../" }
ext-php-rs = { version = "0.14", default-features = false, path = "../../" }

clap = { version = "4.0", features = ["derive"] }
anyhow = "1"
Expand All @@ -22,3 +22,7 @@ semver = "1.0"

[lints.rust]
missing_docs = "warn"

[features]
default = ["enum"]
enum = ["ext-php-rs/enum"]
3 changes: 2 additions & 1 deletion crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/davidcole1340/ext-php-rs"
license = "MIT OR Apache-2.0"
version = "0.11.2"
authors = ["David Cole <[email protected]>"]
edition = "2018"
edition = "2021"

[lib]
proc-macro = true
Expand All @@ -19,6 +19,7 @@ proc-macro2 = "1.0.26"
lazy_static = "1.4.0"
anyhow = "1.0"
convert_case = "0.8.0"
itertools = "0.14.0"

[lints.rust]
missing_docs = "warn"
Expand Down
Loading
Loading