Commit 5c43ef8
authored
[CLI] Load custom PHP.wasm extensions (#3616)
## What it does
Adds Playground CLI support for loading custom PHP.wasm extensions
before PHP
starts:
```bash
wp-playground server \
--php=8.4 \
--php-extension=./dist/wp_mysql_parser/manifest.json
```
`--php-extension` is repeatable and accepts a local path, `file:` URL,
or
`http(s):` URL to a PHP extension manifest.
Manifests can now describe both the artifact matrix and startup settings
in one
JSON file:
```json
{
"name": "spx",
"version": "0.1.0",
"artifacts": [
{
"phpVersion": "8.4",
"sourcePath": "spx-php8.4-jspi.so"
}
],
"iniEntries": {
"spx.http_enabled": "1"
},
"env": {
"SPX_DATA_DIR": "/internal/shared/spx/data"
}
}
```
## Rationale
The PHP.wasm runtime can load externally built JSPI side modules, and
`@php-wasm/compile-extension` emits manifests for those builds. CLI
users still
had no direct way to pass those manifests through to the Node runtime.
Custom extensions must be declared at startup because PHP reads
extension
`.ini` files while booting. Passing manifests through the existing
runtime
`extensions` array keeps CLI behavior aligned with `loadNodeRuntime()`.
The user-facing format is intentionally one manifest file rather than
separate
manifest and loader-config files. Runtime settings such as `iniEntries`,
`env`,
`loadWithIniDirective`, and `extensionDir` live directly in the
manifest.
## Implementation
- Renames the CLI extension adapter to
`cliExtensionArgsToExtensionsArray()`.
- Combines built-in extension flags (`intl`, `redis`, `memcached`,
`xdebug`)
with custom `--php-extension=<manifest>` entries.
- Threads the combined `PHPExtension[]` into both Blueprint v1 and v2
CLI
workers.
- Extends the PHP extension manifest type and generated schema/validator
to
allow runtime startup settings.
- Applies manifest-declared runtime settings in `resolvePHPExtension()`.
- Documents the single manifest-based CLI path in the CLI and
`@php-wasm/compile-extension` READMEs.
## Testing instructions
```bash
npm exec -- nx run playground-cli:test-playground-cli --testFiles=tests/php-extensions.spec.ts
npm exec -- nx run php-wasm-universal:test:vite --testFile=load-extension.spec.ts
npm exec -- nx run playground-cli:typecheck
npm exec -- nx run php-wasm-universal:typecheck
npm exec -- nx run playground-cli:lint
npm exec -- nx run php-wasm-universal:lint
npm exec -- nx run php-wasm-compile-extension:typecheck
npm exec -- nx run php-wasm-compile-extension:lint
git diff --check
```1 parent 90be6be commit 5c43ef8
12 files changed
Lines changed: 1810 additions & 684 deletions
File tree
- packages
- php-wasm
- compile-extension
- src
- universal
- public
- src/lib
- playground/cli
- src
- blueprints-v1
- blueprints-v2
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
47 | 68 | | |
48 | 69 | | |
49 | 70 | | |
| |||
60 | 81 | | |
61 | 82 | | |
62 | 83 | | |
63 | | - | |
| 84 | + | |
64 | 85 | | |
65 | 86 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
71 | 92 | | |
72 | 93 | | |
73 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
38 | 52 | | |
39 | 53 | | |
40 | 54 | | |
| |||
0 commit comments