Skip to content

Commit ef143d3

Browse files
authored
Check Playground web runtime compatibility (#419)
## What? Adds a browser-runtime compatibility check for the `wp_mysql_parser` WASM side modules and wires it into both WASM workflows: - `wasm-spike.yml` - `publish-wasm-extension-artifact.yml` The check compares each side module's `env` function imports against the matching Playground web PHP.wasm runtime exports. It runs for PHP 8.0 through 8.5 so the published manifest cannot claim browser support for a PHP version that will crash during extension startup. Also updates the native extension README/demo URL to use the live `blueprint.json` location and documents PHP 8.0-8.5 browser-runtime coverage instead of the temporary PHP 8.3 pin. ## Why? The previous Node-based smoke test was insufficient: PHP 8.4 loaded in the Node/CLI runtime but crashed in the browser runtime because the web runtime did not export Zend symbols imported by the extension side module. This PR makes that class of failure visible in CI before publishing a WASM manifest. ## Dependency This depends on WordPress/wordpress-playground#3690 and updated Playground web PHP.wasm artifacts. Current Playground web builds are known to miss required exports for PHP 8.0, 8.1, 8.4, and 8.5; the new CI check is expected to pass once those runtime exports ship. ## Testing - `node --check packages/php-ext-wp-mysql-parser/wasm-spike/check-playground-web-compat.mjs` - `git diff --check` - Verified locally with the Playground checkout: - PHP 8.3 currently passes. - PHP 8.4 currently fails with missing `zend_declare_class_constant_ex` and `zend_register_internal_class_ex`, matching the browser crash root cause. ## Note Replacement for #417, which was accidentally opened and merged against `develop` instead of `trunk`.
1 parent 2551090 commit ef143d3

4 files changed

Lines changed: 138 additions & 2 deletions

File tree

‎.github/workflows/publish-wasm-extension-artifact.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ jobs:
109109
/packages/php-wasm/node-builds/8-3/
110110
/packages/php-wasm/node-builds/8-4/
111111
/packages/php-wasm/node-builds/8-5/
112+
/packages/php-wasm/web-builds/8-0/
113+
/packages/php-wasm/web-builds/8-1/
114+
/packages/php-wasm/web-builds/8-2/
115+
/packages/php-wasm/web-builds/8-3/
116+
/packages/php-wasm/web-builds/8-4/
117+
/packages/php-wasm/web-builds/8-5/
112118
/packages/php-wasm/progress/
113119
/packages/php-wasm/scopes/
114120
/packages/php-wasm/stream-compression/
@@ -151,6 +157,14 @@ jobs:
151157
test -f dist/wp_mysql_parser-php${{ matrix.php }}-jspi.so
152158
ls -lh dist/wp_mysql_parser-php${{ matrix.php }}-jspi.so
153159
160+
- name: Check Playground browser runtime compatibility
161+
working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike
162+
env:
163+
PLAYGROUND_REPO: ${{ github.workspace }}/wordpress-playground
164+
PHP_VERSION: ${{ matrix.php }}
165+
ASYNC_MODE: jspi
166+
run: node check-playground-web-compat.mjs
167+
154168
- name: Upload side module
155169
uses: actions/upload-artifact@v4
156170
with:

‎.github/workflows/wasm-spike.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ jobs:
106106
/packages/php-wasm/node-builds/8-3/
107107
/packages/php-wasm/node-builds/8-4/
108108
/packages/php-wasm/node-builds/8-5/
109+
/packages/php-wasm/web-builds/8-0/
110+
/packages/php-wasm/web-builds/8-1/
111+
/packages/php-wasm/web-builds/8-2/
112+
/packages/php-wasm/web-builds/8-3/
113+
/packages/php-wasm/web-builds/8-4/
114+
/packages/php-wasm/web-builds/8-5/
109115
/packages/php-wasm/progress/
110116
/packages/php-wasm/scopes/
111117
/packages/php-wasm/stream-compression/
@@ -161,6 +167,14 @@ jobs:
161167
test -f "dist/$SOURCE_PATH"
162168
node -e "const artifact = require('./dist/manifest.json').artifacts[0]; if ('file' in artifact || 'sha256' in artifact) { throw new Error('manifest uses retired artifact fields'); }"
163169
170+
- name: Check Playground browser runtime compatibility
171+
working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike
172+
env:
173+
PLAYGROUND_REPO: ${{ github.workspace }}/wordpress-playground
174+
PHP_VERSION: ${{ matrix.php }}
175+
ASYNC_MODE: ${{ matrix.async-mode }}
176+
run: node check-playground-web-compat.mjs
177+
164178
- name: Load the extension in Playground and parse a query
165179
working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike
166180
env:

‎packages/php-ext-wp-mysql-parser/README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ The current build is also available directly:
1515
- Manifest: <https://wordpress.github.io/sqlite-database-integration/wp_mysql_parser-wasm-extension/latest/manifest.json>
1616
- Supported PHP versions: 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5.
1717

18-
Use this Playground URL to load the extension and open the demo/benchmark page. The browser demo is pinned to PHP 8.3 because the current Playground browser runtime crashes while loading this extension on PHP 8.4.
18+
Use this Playground URL to load the extension and open the demo/benchmark page.
19+
The published manifest contains PHP 8.0 through 8.5 side modules, and CI checks
20+
that every side module imports only symbols exported by the matching Playground
21+
browser runtime.
1922

20-
<https://playground.wordpress.net/?php=8.3&php-extension=https%3A%2F%2Fwordpress.github.io%2Fsqlite-database-integration%2Fwp_mysql_parser-wasm-extension%2Flatest%2Fmanifest.json&blueprint-url=https%3A%2F%2Fwordpress.github.io%2Fsqlite-database-integration%2Fnative-extension%2Fblueprint.json>
23+
<https://playground.wordpress.net/?php=8.5&php-extension=https%3A%2F%2Fwordpress.github.io%2Fsqlite-database-integration%2Fwp_mysql_parser-wasm-extension%2Flatest%2Fmanifest.json&blueprint-url=https%3A%2F%2Fwordpress.github.io%2Fsqlite-database-integration%2Fblueprint.json>
2124

2225
## Build the native extension locally
2326

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env node
2+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
3+
import { resolve } from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const SPIKE_DIR = resolve(fileURLToPath(new URL('.', import.meta.url)));
7+
const PHP_VERSION = process.env.PHP_VERSION || '8.4';
8+
const ASYNC_MODE = process.env.ASYNC_MODE || 'jspi';
9+
const EXTENSION_NAME = process.env.EXTENSION_NAME || 'wp_mysql_parser';
10+
const SIDE_MODULE = resolve(
11+
process.env.SIDE_MODULE ||
12+
`${SPIKE_DIR}/dist/${EXTENSION_NAME}-php${PHP_VERSION}-${ASYNC_MODE}.so`
13+
);
14+
const PLAYGROUND_REPO = resolve(
15+
process.env.PLAYGROUND_REPO ||
16+
`${SPIKE_DIR}/../../../../wordpress-playground-spike`
17+
);
18+
const EXPECTED_MISSING = new Set(
19+
(process.env.PLAYGROUND_WEB_EXPECTED_MISSING_SYMBOLS || '')
20+
.split(/[\s,]+/)
21+
.filter(Boolean)
22+
);
23+
24+
function findWasmFile(dir) {
25+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
26+
const path = resolve(dir, entry.name);
27+
if (entry.isDirectory()) {
28+
const nested = findWasmFile(path);
29+
if (nested) {
30+
return nested;
31+
}
32+
continue;
33+
}
34+
if (entry.isFile() && entry.name.endsWith('.wasm')) {
35+
return path;
36+
}
37+
}
38+
return null;
39+
}
40+
41+
function loadWasmModule(path) {
42+
if (!existsSync(path)) {
43+
console.error(`[web-compat] Missing ${path}`);
44+
process.exit(2);
45+
}
46+
return new WebAssembly.Module(readFileSync(path));
47+
}
48+
49+
const phpDir = PHP_VERSION.replace('.', '-');
50+
const webBuildDir = resolve(
51+
PLAYGROUND_REPO,
52+
`packages/php-wasm/web-builds/${phpDir}/${ASYNC_MODE}`
53+
);
54+
const webRuntime = findWasmFile(webBuildDir);
55+
if (!webRuntime) {
56+
console.error(`[web-compat] Could not find a PHP.wasm file under ${webBuildDir}`);
57+
process.exit(2);
58+
}
59+
60+
const sideImports = WebAssembly.Module.imports(loadWasmModule(SIDE_MODULE));
61+
const importedFunctions = sideImports
62+
.filter((entry) => entry.module === 'env' && entry.kind === 'function')
63+
.map((entry) => entry.name)
64+
.sort();
65+
const runtimeExports = new Map(
66+
WebAssembly.Module.exports(loadWasmModule(webRuntime)).map((entry) => [
67+
entry.name,
68+
entry.kind,
69+
])
70+
);
71+
const missing = importedFunctions.filter(
72+
(name) => runtimeExports.get(name) !== 'function'
73+
);
74+
const unexpectedMissing = missing.filter((name) => !EXPECTED_MISSING.has(name));
75+
const staleExpectedMissing = [...EXPECTED_MISSING].filter(
76+
(name) => !missing.includes(name)
77+
);
78+
79+
console.log(`[web-compat] PHP ${PHP_VERSION} side module: ${SIDE_MODULE}`);
80+
console.log(`[web-compat] PHP ${PHP_VERSION} web runtime: ${webRuntime}`);
81+
82+
if (unexpectedMissing.length > 0 || staleExpectedMissing.length > 0) {
83+
if (unexpectedMissing.length > 0) {
84+
console.error(
85+
`[web-compat] Missing browser runtime exports: ${unexpectedMissing.join(', ')}`
86+
);
87+
}
88+
if (staleExpectedMissing.length > 0) {
89+
console.error(
90+
`[web-compat] Expected missing exports are now available: ${staleExpectedMissing.join(', ')}`
91+
);
92+
console.error(
93+
'[web-compat] Update the browser demo PHP pin and remove the stale allowlist.'
94+
);
95+
}
96+
process.exit(1);
97+
}
98+
99+
if (missing.length > 0) {
100+
console.log(
101+
`[web-compat] Known browser runtime gap confirmed: ${missing.join(', ')}`
102+
);
103+
} else {
104+
console.log('[web-compat] Browser runtime exports all imported functions.');
105+
}

0 commit comments

Comments
 (0)