Skip to content

Commit 55c8ee0

Browse files
committed
Build WASM extension for all Playground PHP versions
1 parent 2236be3 commit 55c8ee0

5 files changed

Lines changed: 41 additions & 19 deletions

File tree

.github/workflows/wasm-spike.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
php: ['8.4']
29+
php: ['8.5', '8.4', '8.3', '8.2', '8.1', '8.0', '7.4']
3030
async-mode: ['jspi']
3131

3232
steps:
@@ -55,7 +55,13 @@ jobs:
5555
/packages/php-wasm/fs-journal/
5656
/packages/php-wasm/logger/
5757
/packages/php-wasm/node/
58+
/packages/php-wasm/node-builds/7-4/
59+
/packages/php-wasm/node-builds/8-0/
60+
/packages/php-wasm/node-builds/8-1/
61+
/packages/php-wasm/node-builds/8-2/
62+
/packages/php-wasm/node-builds/8-3/
5863
/packages/php-wasm/node-builds/8-4/
64+
/packages/php-wasm/node-builds/8-5/
5965
/packages/php-wasm/progress/
6066
/packages/php-wasm/scopes/
6167
/packages/php-wasm/stream-compression/
@@ -116,6 +122,7 @@ jobs:
116122
working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike
117123
env:
118124
PLAYGROUND_REPO: ${{ github.workspace }}/wordpress-playground
125+
PHP_VERSION: ${{ matrix.php }}
119126
run: node run-spike.mjs
120127

121128
- name: Upload artifacts on success

packages/php-ext-wp-mysql-parser/wasm-spike/Dockerfile.rust

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,47 @@
1111
# Build with:
1212
# docker build \
1313
# --build-arg BASE_IMAGE=playground-php-wasm:compile-extension-php8-4-jspi \
14+
# --build-arg HOST_PHP_VERSION=8.4 \
1415
# -t playground-php-wasm-ext-rust:8.4-jspi \
1516
# -f Dockerfile.rust .
1617

1718
ARG BASE_IMAGE=playground-php-wasm:compile-extension-php8-4-jspi
19+
ARG HOST_PHP_VERSION=8.4
1820

19-
# Stage providing a host PHP 8.4 CLI binary. ext-php-rs's build.rs shells
21+
# Stage providing a host PHP CLI binary. ext-php-rs's build.rs shells
2022
# out to `php` to detect the PHP version (PHP_VERSION_ID drives the cfg
21-
# flags php80..php85). The wasm-targeted PHP install in /usr/local has no
22-
# CLI binary (--disable-cli), Ubuntu noble ships only PHP 8.3, and
23-
# packages.sury.org blocks our datacenter IP, so we steal a CLI from the
24-
# official php:8.4-cli image.
25-
FROM php:8.4-cli AS host-php-cli
23+
# flags such as php74, php80, and php85). The wasm-targeted PHP install in
24+
# /usr/local has no CLI binary (--disable-cli), so copy a matching CLI from
25+
# the official PHP image for the target version.
26+
FROM php:${HOST_PHP_VERSION}-cli AS host-php-cli
27+
28+
RUN set -eux; \
29+
mkdir -p /opt/host-php/libdeps; \
30+
ldd /usr/local/bin/php \
31+
| awk '($2 == "=>") { print $3 } ($1 ~ /^\//) { print $1 }' \
32+
| grep -v '^$' \
33+
| sort -u \
34+
| while read -r lib; do cp -L "$lib" /opt/host-php/libdeps/; done
2635

2736
FROM ${BASE_IMAGE}
2837

2938
COPY --from=host-php-cli /usr/local/bin/php /opt/host-php/bin/php
3039
COPY --from=host-php-cli /usr/local/lib/php /opt/host-php/lib/php
3140
COPY --from=host-php-cli /usr/local/etc/php /opt/host-php/etc/php
3241
COPY --from=host-php-cli /usr/local/include/php /opt/host-php/include/php
42+
COPY --from=host-php-cli /opt/host-php/libdeps /opt/host-php/libdeps
3343

3444
ENV RUSTUP_HOME=/root/rustup \
3545
CARGO_HOME=/root/cargo \
36-
PATH=/root/cargo/bin:/root/rustup/bin:/usr/local/bin:/usr/bin:/bin
46+
PATH=/root/cargo/bin:/root/rustup/bin:/usr/local/bin:/usr/bin:/bin \
47+
LD_LIBRARY_PATH=/opt/host-php/libdeps:/opt/host-php/lib
3748

3849
RUN apt-get update && apt-get install -y --no-install-recommends \
3950
curl ca-certificates build-essential \
4051
libclang-dev clang llvm-dev pkg-config libxml2 libonig5 libsqlite3-0 \
4152
libargon2-1 libssl3 zlib1g libreadline8 \
4253
&& rm -rf /var/lib/apt/lists/* \
54+
&& /opt/host-php/bin/php -v \
4355
&& ln -sf /opt/host-php/bin/php /usr/local/bin/php-host
4456

4557
# ext-php-rs's build.rs needs a host `php` executable to query include paths

packages/php-ext-wp-mysql-parser/wasm-spike/RESULT.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
## Current status
44

5-
The spike now builds and loads `wp_mysql_parser` in Playground on PHP 8.4
6-
JSPI. CI verifies the generated side module by loading its manifest through
7-
Playground's `@php-wasm/compile-extension` test harness and running a native
8-
lexer smoke test.
5+
The spike now builds and loads `wp_mysql_parser` in Playground across every
6+
PHP version currently supported by Playground's `@php-wasm/compile-extension`
7+
helper: 7.4 and 8.0 through 8.5, all JSPI. CI verifies each generated side
8+
module by loading its manifest through Playground's compile-extension test
9+
harness and running a native lexer smoke test.
910

1011
The build uses the upstream Playground compile-extension tooling for the
1112
phpize side-module build, static archive force-linking, wasm-opt pass, and
@@ -27,10 +28,11 @@ Stage 2 path that previously lived in this spike:
2728
- Emits a manifest with `sha256` hashes that the Playground runtime can load
2829
at startup.
2930

30-
The helper is not a full Rust build system. This crate still needs a prebuild
31-
step that produces a wasm32-unknown-emscripten `staticlib`, plus a tiny phpize
32-
shim (`config.m4` and `wp_mysql_parser_shim.c`) so the helper has a normal
33-
extension source directory to compile.
31+
The helper is not a full Rust build system. This crate still needs a
32+
per-PHP-version prebuild step that produces a wasm32-unknown-emscripten
33+
`staticlib` with matching PHP headers and host PHP CLI version, plus a tiny
34+
phpize shim (`config.m4` and `wp_mysql_parser_shim.c`) so the helper has a
35+
normal extension source directory to compile.
3436

3537
## Remaining local compatibility patches
3638

@@ -69,7 +71,7 @@ cd packages/php-ext-wp-mysql-parser/wasm-spike
6971
PLAYGROUND_REPO=/abs/path/to/wordpress-playground \
7072
bash build-in-docker-rust.sh
7173

72-
PLAYGROUND_REPO=/abs/path/to/wordpress-playground \
74+
PLAYGROUND_REPO=/abs/path/to/wordpress-playground PHP_VERSION=8.4 \
7375
node run-spike.mjs
7476
```
7577

packages/php-ext-wp-mysql-parser/wasm-spike/build-in-docker-rust.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
# Outputs:
1414
# wasm-spike/dist/libwp_mysql_parser.a (Stage 1)
15-
# wasm-spike/dist/wp_mysql_parser-php8.4-jspi.so (Stage 2, wasm side module)
15+
# wasm-spike/dist/wp_mysql_parser-php<version>-jspi.so (Stage 2, wasm side module)
1616
# wasm-spike/dist/manifest.json (written by @php-wasm/compile-extension)
1717
set -euo pipefail
1818

@@ -69,6 +69,7 @@ echo "==> Stage 0: preparing $BASE_IMAGE via Playground compile-extension toolin
6969
echo "==> Stage 0: building $RUST_IMAGE"
7070
docker build \
7171
--build-arg "BASE_IMAGE=$BASE_IMAGE" \
72+
--build-arg "HOST_PHP_VERSION=$PHP_VERSION" \
7273
-t "$RUST_IMAGE" \
7374
-f "$SPIKE_DIR/Dockerfile.rust" \
7475
"$SPIKE_DIR"

packages/php-ext-wp-mysql-parser/wasm-spike/run-spike.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { fileURLToPath } from 'node:url';
1616
const here = dirname(fileURLToPath(import.meta.url));
1717
const SPIKE_DIR = here;
1818
const MANIFEST = resolve(SPIKE_DIR, 'dist/manifest.json');
19-
const PHP_VERSION = '8.4';
19+
const PHP_VERSION = process.env.PHP_VERSION || '8.4';
2020

2121
if (!existsSync(MANIFEST)) {
2222
console.error(`[spike] Missing ${MANIFEST}. Run build-in-docker-rust.sh first.`);

0 commit comments

Comments
 (0)