Commit Graph

39 Commits

Author SHA1 Message Date
Joel Wurtz
5fdd8fac44
feat(zend): add helper for try catch and bailout in PHP (#275)
* feat(zend): add helper for try catch and bailout in PHP

* feat(try): add bindings for bailout

* fix(try): add missing feature flag for test

* feat(try): add a test that expose memory leak problem

* feat(try): make bailout unsafe and explain why

* feat(bailout): flag bailout as a panic function

* feat(embed): add try catch on script / eval
2023-10-25 15:15:43 +02:00
Joel Wurtz
2d0e587c7e
feat(embed): add embed features, add test example which run php inside it (#270)
* feat(embed): add embed features, add test example which run php inside it

* feat(embed): use a guard to prevent running in parallel

* chore(ci): update actions to not build and test with embed, add a specific build for embed testing

* feat(embed): correcly start / shutdown embed api

* chore(ci): use stable for rust in embed test

* feat(embed): add documentation, manage potential errors
2023-10-20 14:08:10 +02:00
Pierre Tondereau
63a76846d2
chore: Update bindgen to 0.65.1 (#241) 2023-05-16 22:49:57 +02:00
Ryan McCue
c5eaeb242b
Stop watching Cargo.lock for changes (#232)
When loaded via Cargo, there's no Cargo.lock directly in this crate, so
the lack of file existence causes unnecessary rebuilds every time.
2023-02-24 16:24:19 +01:00
Pierre Tondereau
e6afecbddd
chore(clippy): Fix clippy warnings. (#228) 2023-02-07 22:52:56 +01:00
Pierre Tondereau
11e0998bc4
feat: Add support for PHP 8.2 (#212)
## Small Fixes due to PHP8.2 upgrade:
- Internal PHP `ZendHashmap` changed the way that we access to the bucket ([commit](90b7bde615 (diff-dca4782c62f10b418ea7193e4641e688ffd7a9c97869f2b1a3a96e28da5653aaL371)))
- Internal PHP `ArrayIterator` doesn't support parent `get_iterator` ([commit](15bbf6f337 (diff-bc002b59b592b4d44c13d898f9dc3ca60b1b1c8505a51a2a3557dfde51dfeb61L273)))
2022-12-20 17:11:35 +01:00
Pierre Tondereau
6965f4a198
Prepare v0.9.0 (#211) 2022-12-11 22:10:25 +01:00
ju1ius
4ca5c0d06e
honour PHP_CONFIG & rebuild automatically when env vars change (#210)
Closes https://github.com/davidcole1340/ext-php-rs/issues/208
Closes https://github.com/davidcole1340/ext-php-rs/issues/209

## Summary of the changes

### Build scripts
* the `unix_build.rs` script now honors the `PHP_CONFIG` environment variable, like `cargo php install`
* use `cargo:rerun-if-env-changed` for the `PHP`, `PHP_CONFIG` and `PATH` environment variables, to avoid needless recompilation of the whole dependency tree.

### Documentation
While trying to document the aforementioned changes, I realized that there was no chapter about installing and setting up a PHP environment to develop PHP extensions. So, I refactored the first chapters of the book into a `Getting Started` section, including instructions on how to quickly set up a PHP environment.
2022-12-11 20:08:50 +01:00
Pierre Tondereau
7423da060d
Revert "chore: use php-discovery to find matching PHP build" (#206) 2022-11-28 14:57:34 +01:00
Saif Eddin Gmati
31712066c8
chore: use php-discovery to find matching PHP build (#201) 2022-11-26 13:09:59 -08:00
David Cole
6a598ded3d
fix building docs on docs.rs (#165)
* fix building docs on docs.rs

accidentally removed the docs.rs stub bindings feature in
664981f4fb. docs.rs only has php 7.4 and
therefore cannot build ext-php-rs, so stub bindings are generated prior.

* update docs.rs stub bindings
2022-10-16 12:49:02 +13:00
Tobias Bengtsson
976bc7d686 Fix clippy errors 2022-08-13 18:29:15 +02:00
David Cole
664981f4fb
Windows support (#128)
* Preliminary Windows support

* Start work on cross-platform build script

* Fix compilation on macOS

* Updated README, tidied up build script

* Check linker version before starting compilation

It doesn't seem like it's possible to change the linker from within the
build script, however, we can retrieve the linker in use and give the
user a suggestion if the linker will not work.

* Switch to using Github repository for bindgen

* Split Windows and Unix implementations into two files

* Fix building on Windows

* Remove `reqwest` and `zip` as dependencies on Unix

* Fix guide tests on Windows

* Started work on Windows CI

* runs -> run

* Use preinstalled LLVM on Windows

* Debugging for Windows CI

* Switch to upstream `rust-bindgen` master branch

* Switch to `rust-lld` for Windows linking

* Don't compile `cargo-php` on Windows

* Switch to using skeptic for tests

* cargo-php: Disable stub generation, fix ext install/remove

The plan is to replace the stub generation by generating them with PHP
code. This is cross-platform and means we don't need to worry about ABI.
We also don't need to embed information into the library.

* cargo-php: Fix on unix OS

* Fix clippy lint

* Updated README

* Re-add CI for Unix + PHP 8.0

* Fix building on thread-safe PHP

* Tidy up build scripts

* Use dynamic lookup on Linux, test with TS Windows

* Define `ZTS` when compiling PHP ZTS

* Combine Windows and Unix CI, fix linking for Win32TS

* Fix exclusions in build CI

* rust-toolchain -> rust

* Set LLVM version

* Only build docs.rs on Ubuntu PHP 8.1

* Fix build on Linux thread-safe

* Update guide example
2022-03-18 16:36:51 +13:00
David Cole
75ea32346c
Fix CI on macOS (#126)
* Attempt to fix CI on macOS by not installing LLVM

* Download LLVM even on macOS

* Only set LIBCLANG_PATH on non-macOS

* Fix yaml

* Try to set SDK path for macOS

* Multi-line run

* Clippy lint

* Only check docs on PHP 8.1

* When running with docs stub, use PHP 8.1

* Only build docs on Ubuntu

* Remove `macos-ci` branch from actions

* Trigger actions
2022-03-06 16:01:27 +13:00
David Cole
f9528f07a8 Add shallow_clone to Zval 2021-12-13 22:43:34 +13:00
David Cole
6fd31621f2
Add preliminary PHP 8.1 support (#109)
* Bump PHP API version, remove flags removed from PHP API

See following commits:
- 70195c3561
- b5746a4c7f

* Add PHP 8.1 to CI

* Clippy lint

* Fix PHP 8.1 support with new features
2021-11-21 20:00:51 +13:00
David Cole
6df362b714
Added CLI crate for stubs, installation and removal (#107)
* started work on stub generator

* Worked on stub CLI tool

* Unused import

* Account for namespaces in function and class names

* Add support for docblocks on structs

* Push Rust comments to stubs

* Add indentation to stub generation

* Add CLI application to install and generate stubs

This time CLI application is defined on user side, called with `cargo
run -- ..args..`

* Export anyhow result

* Add constants to stub file

* Removed stub symbols

No longer required as we are now building while also linking to PHP.
Keeping the stubs causes the stubs to override the real symbols in the
extension.

* Fix stubs for real this time

Removed stub symbols as they were being included in the extension
dylib, fix by loading the PHP executable as a dylib, loading the
required symbols globally.

* Maybe actually fix stubs this time

* Forgot to remove PHP binary loading

* let's give this another go... cargo subcommand

Now called via `cargo php <install,stubs>`.

* Added `remove` command

* Tidied up cargo-php, commented, set up CI

* Fix return types with non-ident types

* define namespace ordering

* Fix tests, replace `Self` when in outer context

* Moved allowed bindings into separate file

* Update guide with CLI instructions
2021-11-20 14:19:02 +13:00
David Cole
d74b5d54b7 Clean up clippy lints 2021-11-05 23:45:58 +13:00
David Cole
88b84b9a17
Disable serialization and unserialization on classes (#105)
* Disable serialization and unserialization on classes

Classes that have associated Rust types cannot be serialized for
obvious reasons so these need to be disabled. Disabling these actions
changes in PHP 8.1 to use a flag, so that will need to be solved with
PHP 8.1 support. Closes #97

* update docs stubs
2021-10-19 02:10:02 +13:00
David Cole
466c1658e3
Refactor module paths (#101)
* Refactor module layout

* Fixed documentation tests

* Removed skel, moved macro crate

* Ignore folders for crate publish

* Fix builder for zts

* Add `rustfmt.toml`, wrap all comments #96

* Fixed up documentation links, tidied up

* Add `Zend` prefix to callable and hashtable

* Updated guide types

* Updated changelog
2021-10-10 17:51:55 +13:00
David
3403cba7bf
Add ZBox<T> to replace owned variants (#94)
* Added `ZBox` and `ZBoxable`

* Implement `ZBoxable` for `ZendStr`

Build for all f eatures on CI

* Replace `OwnedZendObject` with `ZBox<ZendObject>`

* Replace `ClassObject` with `ZBox<ZendClassObject>`

Fixed deserialization bug

Panic when uninitialized - better than UB

* Replace `OwnedHashTable` with `ZBox<HashTable>`

* Remove `MaybeUninit` from `ZendClassObject`
2021-10-05 16:59:41 +13:00
David
c16c5d48cb
Add #[derive(ZvalConvert)] macro (#78) 2021-10-03 18:00:50 +13:00
Simon Gomizelj
0f2cabbd95
Add Display impl for ZendObject (#74)
* Add support to capture execptions from PHP

* Add extract function to Zval

* Add FromZendObject trait for casting objects to other types
2021-10-03 14:37:55 +13:00
David
afdac8e4b3
Add support for field and method properties (#69)
* Rough implementation of struct properties

* Store properties hashtable once

* Tidy up handler functions with exceptions

* Add stub `get_properties` function for codegen structs

* Remove nightly features

* Revert storing properties

Technically, the zend object _could_ move in memory, leaving dangling
references in the properties hashtable. We will just build the hashtable
when required.

* Added `#[prop]` attribute

* Add pointer type to zval, tidy up zend string

* Add support for method properties

* Add `#[getter]` and `#[setter]` attributes

* Update documentation with method properties

* Tidy up macros code

* Remove string gc checks (done on PHP side)

* Move `RegisteredClass` implementation to module, update docs

* Fix read property `rv` segfault

* Fixed doctests
2021-09-28 00:54:23 +13:00
David
aea8717456
Refactor Zend strings (#77)
* Call zval destructor when changing zval type and dropping

* Remove `ZendHashTable` wrapper

Replaced by returning references to the actual hashtable, and having a
new type `OwnedHashTable` when creating a new hashtable.

* Refactor `ZendString` into a borrowed and owned variant

`&ZendStr` is now equivalent to `&str`, while `ZendString` is equivalent
to `String`.

* Tidy up `ZendString`, add `Debug` implementation
2021-09-28 00:33:16 +13:00
David
7c484a0e18
Refactor ZendHashTable and Zval (#76)
* Call zval destructor when changing zval type and dropping

* Remove zval return from array insert functions #73

The functions actually returned references to the new zval value, so
there's not much point in returning.

* Remove `ZendHashTable` wrapper

Replaced by returning references to the actual hashtable, and having a
new type `OwnedHashTable` when creating a new hashtable.

* Remove pointless `drop` field from `OwnedHashTable`

* Added `Values` iterator for Zend hashtable

* Change iterators to double ended and exact size
2021-09-21 21:22:05 +12:00
David
f506a41b3c
Pass class object type to PHP when taking object parameter (#64)
* Pass class object type to PHP when taking object parameter

* Fix test

* Update docs.rs stub bindings
2021-09-08 22:21:21 +12:00
David Cole
356c1fdd97 Add support for docs.rs (hopefully) 2021-09-05 18:18:09 +12:00
David
b50a6c64bf
Allowlist types generated by bindgen (#60)
* Allowlist types generated by bindgen

Tidied up build script as well, layout tests are no longer generated
unless `EXT_PHP_RS_TEST` env variable is set. Much quicker build times
and smaller output size.

* Fix build

* Override Rust toolchain when running CI
2021-09-05 17:56:29 +12:00
David
52fae5c6d4
Use configuration tags instead of features for flags (#59)
e.g. PHP debug or ZTS mode are no longer features, but just simply
configuration flags.
2021-09-05 14:49:50 +12:00
David
73526d62b5
Drop object contents rather than deallocating whole object (#57)
The object memory is automatically deallocated, however, anything that
has been allocated on the heap (strings, vectors etc.) must be
deallocated while we are freeing the object.
2021-09-05 00:53:29 +12:00
David
84aaa07d3e
Add abstraction macros (#49)
* Remove uses of `unwrap`, improve library safety

* Started work on `#[php_function]` attribute

* Added `PhantomData` to `ZendHashTable`

Proper lifetimes for `HashTable` type

* `#[php_function]` now accepts `Vec<T>`

Refactored `ZendHashTable` iterators - there is now `Iter` and
`IntoIter` depending on whether it will consume the HashTable or not.

* Add support for nullable types

* Allow `optional` parameter on attribute

* Support primitive and `Option` return types

* Tidied and refactored attribute

* Added documentation for `#[php_function]`

Implemented `IntoZval` for `Option<T>` when `IntoZval` is also
implemented for `T`. `None` resolves to `null`.

* Added `#[php_method]` attribute

* Added `Callable` type, implemented `Drop` on `Zval`

While implementing `Drop`, the `Copy` derivation was removed, however,
this should not have been there in the first place (`Zval` is not valid
for `Copy` if it contains a string).

* Added some macro functions to example

* Add support for boolean arguments

* Added wrapper around binary data

Future support for binary arguments with `#[php_function]` macros.
Unpacking binary data is no longer unsafe. It was never really unsafe in
the beginning, as we were always reading valid memory, just the contents
of the data could not be trusted.

* Added `#[php_module]` attribute, added support for binary arguments

* Added defaults for functions

* Add defaults for methods

* Add startup function macro and prelude

* Refactored method adding

Now done through impl attribute

* Don't rename functions - generate another internal fn

Also hide all generated functions from docs

* Generate startup function when not already defined

* Add support for class and global constants

* Updated `skel` project

* Updated macro documentation, added executor globals

* Remove `Copy` bound for HashMap to Zval

* Updated documentation

* Add `FromZval` trait, updated docs

* Fixed clippy lints

* Fixed ZTS executor globals

* Fix clippy lint
2021-08-18 13:15:25 +12:00
David
0db6888c46
Added support for PHP ZTS (#37)
* Added support for PHP ZTS

* Added GitHub action for ZTS

Runs seperate from the other tests, as the setup-php action does not
support ZTS, therefore we run the tests in a Docker container.

* Source Rust env file before building

* No `source` command on docker

* Another attempt at fixing Rust in Docker
2021-05-19 20:45:39 +12:00
David
e4deb1f93f
Implemented classes (#17)
* Add PHP thread safety to build matrix

* Revert "Add PHP thread safety to build matrix"

This reverts commit 7de868e6b6e329b87c412af8daf61cba1a3e29c5.

* Fixed arguments not being reconized by PHP

* Added function to create interned Zend string

* Changed statup/shutdown function types to Rust types

Prevents users having to import from bindings

* Added flags for classes

* WIP: class builder

* Added properties to classes

* Added class constants

* Added PHP base extensions
Added class inheritance

* Fixed memory leak with constants

Created C wrapper which is compiled and linked in the `build.rs`
script. In the process removed the `build_id()` function as now
we can just export the macro via a function which is defined in
`wrapper.c`.

* Fixed lint issue

* Added functions to set zval as different strings

Regular strings, persistent strings and interned strings

* Updated README with requirements

* Fixed lint issues

* Changed properties to use proper function

* Free zend string when it is changed for a persistent one

* WIP: overriding zend objects

* Added comments to the top of modules.

* Fixed some comments

* Initialize hash map with initial size when converting from HashMap and
Vec

* Removed unused imports

* WIP: object overrides

* Added DerefMut implementation for ZendClassObject

Tidied up lints that clippy was complaining about, removed debugging
statements.

* Fixed pointer dereference error in macro

* Added missing comments for trait

* All functions now take mutable references vs ptr

Removed SetZval implementation for *mut Zval.
Made bindings public, removed duplicate bindings.
Fixed `create_object` handler not working.
Note to self: smaller commits.

* Showcase ability to use shared object

* WIP: debugging property errors

Changed `function` to `method` in classes
Fixed doctest for `c_str`

* Disabled class properties temporarily

See #16

* Initialize args array with size
2021-04-02 14:18:45 +13:00
David
e1ca2129fe
Add github actions for building and linting (#12)
* Added github build workflow

* Added lint workflow

* Fixed clippy errors

* Fixed clippy warnings

* Allow warnings on generated code

* Final clippy fix... hopefully
2021-03-11 13:41:05 +13:00
David
2a8313bb68
Check PHP API version in build script (#11)
Ensure that the user is compiling with a supported version
of PHP.
2021-03-11 12:34:47 +13:00
David Cole
7587dccd0d added module builder, example project, documentation 2021-03-09 20:47:20 +13:00
David Cole
50d774ee31 added info table headers
infotable class is deprecated
2021-03-09 16:28:37 +13:00
David Cole
61ed3c8a15 initial commit
added php wrapper
2021-03-09 12:40:12 +13:00