Skip to content

Commit f4fd27e

Browse files
authored
chore(bindings): add tooling to generate docsrs_bindings.rs
Refs: #443
1 parent 1ade4eb commit f4fd27e

File tree

8 files changed

+116
-9
lines changed

8 files changed

+116
-9
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
/guide

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ env:
1111
# increment this manually to force cache eviction
1212
RUST_CACHE_PREFIX: "v0-rust"
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
17+
1418
jobs:
1519
lint:
1620
name: Lint

.github/workflows/docsrs_bindings.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: docsrs bindings
2+
on:
3+
pull_request:
4+
paths:
5+
- 'allowed-bindings.rs'
6+
- 'docsrs_bindings.rs'
7+
- 'Cargo.toml'
8+
- 'build.rs'
9+
- 'Dockerfile'
10+
- '.dockerignore'
11+
- 'tools/update_bindings.sh'
12+
- '.github/workflows/docsrs_bindings.yml'
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
lint-bindings:
20+
name: Lint bindings
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
- name: Check docsrs_bindings.rs
28+
run: tools/update_bindings.sh && git diff --exit-code docsrs_bindings.rs

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM rust:latest AS base
2+
ARG PHP_VERSION=8.4
3+
WORKDIR /tmp
4+
RUN <<EOF
5+
set -e
6+
7+
apt update -y
8+
apt install -y \
9+
libclang-dev \
10+
bison \
11+
re2c
12+
13+
# Build PHP
14+
git clone --depth 1 -b PHP-${PHP_VERSION} https://github.com/php/php-src.git
15+
cd php-src
16+
# by default you will be on the master branch, which is the current
17+
# development version. You can check out a stable branch instead:
18+
./buildconf
19+
./configure \
20+
--enable-debug \
21+
--disable-all --disable-cgi
22+
make -j "$(nproc)"
23+
make install
24+
EOF
25+
26+
FROM base AS docsrs_bindings_builder
27+
WORKDIR /src
28+
RUN rustup component add rustfmt
29+
RUN --mount=type=bind,target=/src,rw <<EOF
30+
set -e
31+
cargo clean
32+
cargo build
33+
cp target/debug/build/ext-php-rs-*/out/bindings.rs /docsrs_bindings.rs
34+
rustfmt /docsrs_bindings.rs
35+
EOF
36+
ENTRYPOINT ["/generate.sh"]
37+
38+
FROM scratch AS docsrs_bindings
39+
COPY --from=docsrs_bindings_builder /docsrs_bindings.rs /

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,26 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
201201
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
202202
dual licensed as above, without any additional terms or conditions.
203203

204+
## Development
205+
206+
### `allowed_bindings.rs`
207+
This file contains the list of allowed bindings for the Zend API. It is acting
208+
as a whitelist for the bindings that can be used in the library.
209+
210+
When updating this file you need to also update the `docsrs_bindings.rs` file.
211+
To do this, run the following command from the root of the project:
212+
213+
```bash
214+
tools/update_bindings.sh
215+
```
216+
217+
This will build the bindings using docker, and then copy the `docsrs_bindings.rs`
218+
file to the root of the repository.
219+
This will ensure that the file is always built in the same environment.
220+
221+
Docker and buildx are required to run the script, so make sure you have
222+
those [installed](https://docs.docker.com/engine/install/).
223+
204224
## Resources
205225

206226
- [PHP Internals Book](https://www.phpinternalsbook.com/)

allowed_bindings.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
//
88
// NOTE TO EDITORS:
99
// When updating this file, you must re-generate the `docsrs_bindings.rs`
10-
// file used by docs.rs to build documentation. To perform this:
10+
// file used by docs.rs to build documentation. To perform this from
11+
// within the repository root:
1112
//
12-
// $ cargo clean
13-
// $ cargo build
14-
// $ cp target/debug/build/ext-php-rs-e2cb315d27898d01/out/bindings.rs
15-
// docsrs_bindings.rs
13+
// $ tools/update_bindings.sh
1614
// $ git add . && git commit -m "update docs.rs bindings"
1715
//
18-
// The hash after `ext-php-rs-` in the bindings path may change. There should
19-
// be two folders beginning with `ext-php-rs-` in `target/debug/build`, so
20-
// check both for the presence of the bindings file.
16+
// This will build the bindings using docker, and then copy the
17+
// `docsrs_bindings.rs` file to the root of the repository.
18+
// This will ensure that the file is always built in the same environment.
19+
//
20+
// Docker and buildx are required to run the script, so make sure you have
21+
// those installed. For more information, see:
22+
// https://docs.docker.com/engine/install/
2123

2224
bind! {
2325
HashTable,

docsrs_bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub struct _IO_FILE {
270270
pub _wide_data: *mut _IO_wide_data,
271271
pub _freeres_list: *mut _IO_FILE,
272272
pub _freeres_buf: *mut ::std::os::raw::c_void,
273-
pub _prevchain: *mut *mut _IO_FILE,
273+
pub __pad5: usize,
274274
pub _mode: ::std::os::raw::c_int,
275275
pub _unused2: [::std::os::raw::c_char; 20usize],
276276
}

tools/update_bindings.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
# This script updates the bindings for the docs.rs documentation.
3+
# It should be run from the root of the repository.
4+
#
5+
# This script requires docker to be installed and running.
6+
set -e
7+
8+
docker buildx build \
9+
--target docsrs_bindings \
10+
-o type=local,dest=. \
11+
--build-arg PHP_VERSION=8.3 \
12+
.

0 commit comments

Comments
 (0)