Skip to content

Commit c438b9c

Browse files
Merge branch 'master' of https://github.com/davidcole1340/ext-php-rs into feat-integration-tests
2 parents eb4c9dd + faa452e commit c438b9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1269
-490
lines changed

.cargo/config

Lines changed: 0 additions & 2 deletions
This file was deleted.

.cargo/config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[target.'cfg(not(target_os = "windows"))']
2+
rustflags = ["-C", "link-arg=-Wl,-undefined,dynamic_lookup"]
3+
4+
[target.x86_64-pc-windows-msvc]
5+
linker = "rust-lld"
6+
7+
[target.i686-pc-windows-msvc]
8+
linker = "rust-lld"

.github/workflows/build.yml

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,105 +8,82 @@ on:
88
jobs:
99
build:
1010
name: Build and Test
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os:
15-
- ubuntu-latest
16-
- macos-latest
17-
rust-toolchain:
18-
- stable
19-
- nightly
20-
php:
21-
- '8.0'
22-
- '8.1'
23-
llvm:
24-
- '11.0'
14+
os: [ubuntu-latest, macos-latest, windows-latest]
15+
php: ['8.0', '8.1']
16+
rust: [stable, nightly]
17+
phpts: [ts, nts]
18+
exclude:
19+
# ext-php-rs requires nightly Rust when on Windows.
20+
- os: windows-latest
21+
rust: stable
22+
# setup-php doesn't support thread safe PHP on Linux and macOS.
23+
- os: macos-latest
24+
phpts: ts
25+
- os: ubuntu-latest
26+
phpts: ts
2527
steps:
2628
- name: Checkout code
2729
uses: actions/checkout@v2
2830
- name: Setup PHP
2931
uses: shivammathur/setup-php@v2
3032
with:
3133
php-version: ${{ matrix.php }}
34+
env:
35+
phpts: ${{ matrix.phpts }}
3236
- name: Setup Rust
3337
uses: actions-rs/toolchain@v1
3438
with:
35-
toolchain: ${{ matrix.rust-toolchain }}
39+
toolchain: ${{ matrix.rust }}
3640
override: true
41+
components: rustfmt, clippy
3742
- name: Setup LLVM & Clang
43+
if: "!contains(matrix.os, 'windows')"
44+
id: clang
3845
uses: KyleMayes/install-llvm-action@v1
3946
with:
40-
version: ${{ matrix.llvm }}
41-
directory: ${{ runner.temp }}/llvm-${{ matrix.llvm }}
42-
- name: Install mdbook
43-
uses: peaceiris/actions-mdbook@v1
44-
with:
45-
mdbook-version: latest
47+
version: '13.0'
48+
directory: ${{ runner.temp }}/llvm
49+
- name: Configure Clang
50+
if: "!contains(matrix.os, 'windows')"
51+
run: |
52+
echo "LIBCLANG_PATH=${{ runner.temp }}/llvm/lib" >> $GITHUB_ENV
53+
echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV
54+
- name: Configure Clang (macOS only)
55+
if: "contains(matrix.os, 'macos')"
56+
run: echo "SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
4657
- name: Build
4758
env:
48-
LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.llvm }}/lib
4959
EXT_PHP_RS_TEST:
5060
run: cargo build --release --all-features --all
51-
- name: Test guide examples
52-
env:
53-
CARGO_PKG_NAME: mdbook-tests
54-
CARGO_PKG_VERSION: 0.1.0
55-
run: |
56-
mdbook test guide -L target/release/deps
5761
- name: Test inline examples
5862
uses: actions-rs/cargo@v1
59-
env:
60-
LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.llvm }}/lib
6163
with:
6264
command: test
63-
args: --release --all
64-
build-zts:
65-
name: Build with ZTS
66-
runs-on: ubuntu-latest
67-
steps:
68-
- name: Checkout code
69-
uses: actions/checkout@v2
70-
- name: Build
71-
uses: ./.github/actions/zts
72-
lint:
73-
name: Lint
74-
runs-on: ubuntu-latest
75-
strategy:
76-
matrix:
77-
llvm:
78-
- '11.0'
79-
steps:
80-
- name: Checkout code
81-
uses: actions/checkout@v2
82-
- name: Setup Rust
83-
uses: actions-rs/toolchain@v1
84-
with:
85-
profile: minimal
86-
toolchain: stable
87-
override: true
88-
components: rustfmt, clippy
89-
- name: Setup LLVM & Clang
90-
uses: KyleMayes/install-llvm-action@v1
91-
with:
92-
version: ${{ matrix.llvm }}
93-
directory: ${{ runner.temp }}/llvm-${{ matrix.llvm }}
65+
args: --release --all --all-features
9466
- name: Run rustfmt
9567
uses: actions-rs/cargo@v1
96-
env:
97-
LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.llvm }}/lib
9868
with:
9969
command: fmt
10070
args: --all -- --check
10171
- name: Run clippy
10272
uses: actions-rs/cargo@v1
103-
env:
104-
LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.llvm }}/lib
10573
with:
10674
command: clippy
10775
args: --all -- -D warnings
10876
- name: Build with docs stub
77+
if: "contains(matrix.os, 'ubuntu') && matrix.php == '8.1'"
10978
env:
11079
DOCS_RS:
11180
run:
11281
cargo clean && cargo build
82+
build-zts:
83+
name: Build with ZTS
84+
runs-on: ubuntu-latest
85+
steps:
86+
- name: Checkout code
87+
uses: actions/checkout@v2
88+
- name: Build
89+
uses: ./.github/actions/zts

Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repository = "https://github.com/davidcole1340/ext-php-rs"
55
homepage = "https://github.com/davidcole1340/ext-php-rs"
66
license = "MIT OR Apache-2.0"
77
keywords = ["php", "ffi", "zend"]
8-
version = "0.7.3"
8+
version = "0.7.4"
99
authors = ["David Cole <[email protected]>"]
1010
edition = "2018"
1111
categories = ["api-bindings"]
@@ -17,12 +17,22 @@ parking_lot = "0.11.2"
1717
cfg-if = "1.0"
1818
once_cell = "1.8.0"
1919
anyhow = { version = "1", optional = true }
20-
ext-php-rs-derive = { version = "=0.7.3", path = "./crates/macros" }
20+
ext-php-rs-derive = { version = "=0.7.4", path = "./crates/macros" }
21+
22+
[dev-dependencies]
23+
skeptic = "0.13"
2124

2225
[build-dependencies]
23-
bindgen = { version = "0.59" }
24-
regex = "1"
26+
anyhow = "1"
27+
# bindgen = { version = "0.59" }
28+
bindgen = { git = "https://github.com/rust-lang/rust-bindgen", branch = "master" }
2529
cc = "1.0"
30+
skeptic = "0.13"
31+
32+
[target.'cfg(windows)'.build-dependencies]
33+
ureq = { version = "2.4", features = ["native-tls", "gzip"], default-features = false }
34+
native-tls = "0.2"
35+
zip = "0.5"
2636

2737
[features]
2838
closure = []

README.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# ext-php-rs
22

3-
[<img align="right" src="https://discord.com/api/guilds/115233111977099271/widget.png?style=banner2">](https://discord.gg/dphp)
3+
[![Crates.io](https://img.shields.io/crates/v/ext-php-rs)](https://lib.rs/ext-php-rs)
4+
[![docs.rs](https://img.shields.io/docsrs/ext-php-rs/latest)](https://docs.rs/ext-php-rs)
5+
[![Guide Workflow Status](https://img.shields.io/github/workflow/status/davidcole1340/ext-php-rs/Deploy%20documentation?label=guide)](https://davidcole1340.github.io/ext-php-rs)
6+
![CI Workflow Status](https://img.shields.io/github/workflow/status/davidcole1340/ext-php-rs/Build%20and%20Lint)
7+
[![Discord](https://img.shields.io/discord/115233111977099271)](https://discord.gg/dphp)
48

59
Bindings and abstractions for the Zend API to build PHP extensions natively in
610
Rust.
711

12+
- Documentation: <https://docs.rs/ext-php-rs>
13+
- Guide: <https://davidcole1340.github.io/ext-php-rs>
14+
815
## Example
916

1017
Export a simple function `function hello_world(string $name): string` to PHP:
1118

1219
```rust
20+
#![cfg_attr(windows, feature(abi_vectorcall))]
21+
1322
use ext_php_rs::prelude::*;
1423

1524
/// Gives you a nice greeting!
@@ -104,16 +113,37 @@ best resource at the moment. This can be viewed at [docs.rs].
104113

105114
## Requirements
106115

107-
- PHP 8.0 or later
108-
- No support is planned for lower versions.
109-
- Linux or Darwin-based OS
110-
- Rust - no idea which version
111-
- Clang 3.9 or greater
112-
113-
See the following links for the dependency crate requirements:
114-
115-
- [`cc`](https://github.com/alexcrichton/cc-rs#compile-time-requirements)
116-
- [`bindgen`](https://rust-lang.github.io/rust-bindgen/requirements.html)
116+
- Linux, macOS or Windows-based operating system.
117+
- PHP 8.0 or later.
118+
- No support is planned for earlier versions of PHP.
119+
- Rust.
120+
- Currently, we maintain no guarantee of a MSRV, however lib.rs suggests Rust
121+
1.57 at the time of writing.
122+
- Clang 5.0 or later.
123+
124+
### Windows Requirements
125+
126+
- Extensions can only be compiled for PHP installations sourced from
127+
<https://windows.php.net>. Support is planned for other installations
128+
eventually.
129+
- Rust nightly is required for Windows. This is due to the [vectorcall] calling
130+
convention being used by some PHP functions on Windows, which is only
131+
available as a nightly unstable feature in Rust.
132+
- It is suggested to use the `rust-lld` linker to link your extension. The MSVC
133+
linker (`link.exe`) is supported however you may run into issues if the linker
134+
version is not supported by your PHP installation. You can use the `rust-lld`
135+
linker by creating a `.cargo\config.toml` file with the following content:
136+
```toml
137+
# Replace target triple if you have a different architecture than x86_64
138+
[target.x86_64-pc-windows-msvc]
139+
linker = "rust-lld"
140+
```
141+
- The `cc` crate requires `cl.exe` to be present on your system. This is usually
142+
bundled with Microsoft Visual Studio.
143+
- `cargo-php`'s stub generation feature does not work on Windows. Rewriting this
144+
functionality to be cross-platform is on the roadmap.
145+
146+
[vectorcall]: https://docs.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-170
117147

118148
## Cargo Features
119149

@@ -126,16 +156,13 @@ All features are disabled by default.
126156

127157
## Usage
128158

129-
This project only works for PHP >= 8.0 (for now). Due to the fact that the PHP
130-
extension system relies heavily on C macros (which cannot be exported to Rust
131-
easily), structs have to be hard coded in.
132-
133159
Check out one of the example projects:
134160

135161
- [anonaddy-sequoia](https://gitlab.com/willbrowning/anonaddy-sequoia) - Sequoia
136162
encryption PHP extension.
137-
- [opus-php](https://github.com/davidcole1340/opus-php) -
138-
Audio encoder for the Opus codec in PHP.
163+
- [opus-php](https://github.com/davidcole1340/opus-php) - Audio encoder for the
164+
Opus codec in PHP.
165+
- [tomlrs-php](https://github.com/jphenow/tomlrs-php) - TOML data format parser.
139166

140167
## Contributions
141168

allowed_bindings.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ bind! {
2323
_zend_new_array,
2424
_zval_struct__bindgen_ty_1,
2525
_zval_struct__bindgen_ty_2,
26-
ext_php_rs_executor_globals,
27-
ext_php_rs_php_build_id,
28-
ext_php_rs_zend_object_alloc,
29-
ext_php_rs_zend_object_release,
30-
ext_php_rs_zend_string_init,
31-
ext_php_rs_zend_string_release,
26+
// ext_php_rs_executor_globals,
27+
// ext_php_rs_php_build_id,
28+
// ext_php_rs_zend_object_alloc,
29+
// ext_php_rs_zend_object_release,
30+
// ext_php_rs_zend_string_init,
31+
// ext_php_rs_zend_string_release,
3232
object_properties_init,
3333
php_info_print_table_end,
3434
php_info_print_table_header,
@@ -165,8 +165,8 @@ bind! {
165165
ZEND_DEBUG,
166166
ZEND_HAS_STATIC_IN_METHODS,
167167
ZEND_ISEMPTY,
168-
ZEND_MM_ALIGNMENT,
169-
ZEND_MM_ALIGNMENT_MASK,
168+
// ZEND_MM_ALIGNMENT,
169+
// ZEND_MM_ALIGNMENT_MASK,
170170
ZEND_MODULE_API_NO,
171171
ZEND_PROPERTY_EXISTS,
172172
ZEND_PROPERTY_ISSET,
@@ -189,8 +189,13 @@ bind! {
189189
zend_standard_class_def,
190190
zend_class_serialize_deny,
191191
zend_class_unserialize_deny,
192+
zend_executor_globals,
192193
zend_objects_store_del,
193194
gc_possible_root,
194195
ZEND_ACC_NOT_SERIALIZABLE,
195-
executor_globals
196+
executor_globals,
197+
php_printf,
198+
__zend_malloc,
199+
tsrm_get_ls_cache,
200+
executor_globals_offset
196201
}

0 commit comments

Comments
 (0)