Skip to content

Commit 25f508f

Browse files
authored
feat(enum): add basic enum support
* feat(enum): add basic enum support Fixes: #178 Refs: #302 * feat(enum): add support for string backed enums Refs: #178 * ci(enum): exclude `enum` feature on PHP 8.0 Refs: #178 * feat(enum): implement `IntoZval` and `FromZval` for enums Refs: #178 * feat(enum): implement `TryFrom` and `Into` for backed enum Refs: #178 * feat(enum): add stub generation Refs: #178 * docs(enum): extend enum documentation Refs: #178 * refactor(enum): use `value` for discriminants to be less verbose Refs: #178 * test(enum): add enum testcases Refs: #178 * refactor(enum): use raii box pattern for enum values Refs: #178
1 parent f4a7bd4 commit 25f508f

File tree

30 files changed

+1734
-41
lines changed

30 files changed

+1734
-41
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
env:
8181
DOCS_RS: ""
8282
run: cargo clean && cargo build
83+
8384
build:
8485
name: Build and Test
8586
runs-on: ${{ matrix.os }}
@@ -161,12 +162,12 @@ jobs:
161162
- name: Build
162163
env:
163164
EXT_PHP_RS_TEST: ""
164-
run: cargo build --release --features closure,anyhow --all
165+
run: cargo build --release --features closure,anyhow --workspace ${{ matrix.php == '8.0' && '--no-default-features' || '' }}
165166
# Test
166167
- name: Test inline examples
167168
# Macos fails on unstable rust. We skip the inline examples test for now.
168169
if: "!(contains(matrix.os, 'macos') && matrix.rust == 'nightly')"
169-
run: cargo test --release --all --features closure,anyhow --no-fail-fast
170+
run: cargo test --release --workspace --features closure,anyhow --no-fail-fast ${{ matrix.php == '8.0' && '--no-default-features' || '' }}
170171
build-zts:
171172
name: Build with ZTS
172173
runs-on: ubuntu-latest

.github/workflows/coverage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: coverage
22
on:
33
push:
44
branches-ignore:
5-
- 'release-plz-*'
5+
- "release-plz-*"
66
pull_request:
77
branches-ignore:
8-
- 'release-plz-*'
8+
- "release-plz-*"
99
env:
1010
# increment this manually to force cache eviction
1111
RUST_CACHE_PREFIX: "v0-rust"
@@ -63,6 +63,6 @@ jobs:
6363
cargo tarpaulin --version
6464
- name: Run tests
6565
run: |
66-
cargo tarpaulin --engine llvm --workspace --all-features --tests --exclude tests --exclude-files docsrs_bindings.rs --timeout 120 --out Xml
66+
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
6767
- name: Upload coverage
6868
uses: coverallsapp/github-action@v2

.lefthook.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pre-commit:
1717
The `docsrs_bindings.rs` file seems to be out of date.
1818
Please check the updated bindings in `docsrs_bindings.rs` and commit the changes.
1919
- name: "macro docs"
20-
run: tools/update_lib_docs.sh && git diff --exit-code crates/macros/src/lib.rs
21-
glob: "guide/src/macros/*.md"
22-
fail_text: |
23-
The macro crates documentation seems to be out of date.
24-
Please check the updated documentation in `crates/macros/src/lib.rs` and commit the changes.
20+
run: tools/update_lib_docs.sh
21+
glob:
22+
- "guide/src/macros/*.md"
23+
- "crates/macros/src/lib.rs"
24+
stage_fixed: true

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ native-tls = "0.2"
3838
zip = "4.0"
3939

4040
[features]
41+
default = ["enum"]
4142
closure = []
4243
embed = []
4344
anyhow = ["dep:anyhow"]
45+
enum = []
4446

4547
[workspace]
4648
members = [

allowed_bindings.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ bind! {
8787
zend_declare_class_constant,
8888
zend_declare_property,
8989
zend_do_implement_interface,
90+
zend_enum_add_case,
91+
zend_enum_get_case,
92+
zend_enum_new,
9093
zend_execute_data,
9194
zend_function_entry,
9295
zend_hash_clean,
@@ -114,6 +117,7 @@ bind! {
114117
zend_register_bool_constant,
115118
zend_register_double_constant,
116119
zend_register_ini_entries,
120+
zend_register_internal_enum,
117121
zend_ini_entry_def,
118122
zend_register_internal_class_ex,
119123
zend_register_long_constant,
@@ -191,6 +195,7 @@ bind! {
191195
ZEND_ACC_DEPRECATED,
192196
ZEND_ACC_DONE_PASS_TWO,
193197
ZEND_ACC_EARLY_BINDING,
198+
ZEND_ACC_ENUM,
194199
ZEND_ACC_FAKE_CLOSURE,
195200
ZEND_ACC_FINAL,
196201
ZEND_ACC_GENERATOR,

build.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
261261
Ok(bindings)
262262
}
263263

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

273273
impl ApiVersion {
274274
/// Returns the minimum API version supported by ext-php-rs.
275-
pub const fn min() -> Self {
276-
ApiVersion::Php80
275+
pub fn min() -> Self {
276+
[
277+
ApiVersion::Php80,
278+
#[cfg(feature = "enum")]
279+
ApiVersion::Php81,
280+
]
281+
.into_iter()
282+
.max()
283+
.unwrap_or(Self::max())
277284
}
278285

279286
/// Returns the maximum API version supported by ext-php-rs.

crates/cli/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ edition = "2018"
1111
categories = ["api-bindings", "command-line-interface"]
1212

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

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

2323
[lints.rust]
2424
missing_docs = "warn"
25+
26+
[features]
27+
default = ["enum"]
28+
enum = ["ext-php-rs/enum"]

crates/macros/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ homepage = "https://github.com/davidcole1340/ext-php-rs"
66
license = "MIT OR Apache-2.0"
77
version = "0.11.2"
88
authors = ["David Cole <[email protected]>"]
9-
edition = "2018"
9+
edition = "2021"
1010

1111
[lib]
1212
proc-macro = true
@@ -19,6 +19,7 @@ proc-macro2 = "1.0.26"
1919
lazy_static = "1.4.0"
2020
anyhow = "1.0"
2121
convert_case = "0.8.0"
22+
itertools = "0.14.0"
2223

2324
[lints.rust]
2425
missing_docs = "warn"

0 commit comments

Comments
 (0)