Skip to content

Commit 94e808c

Browse files
committed
Support staging PHP.wasm side modules
1 parent c2e504e commit 94e808c

11 files changed

Lines changed: 1379 additions & 662 deletions

File tree

packages/php-wasm/node/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ URL. Relative local paths are resolved from the current working directory.
6363
Relative artifact files in the manifest are resolved against the manifest
6464
location.
6565

66+
Set `loadWithIniDirective: false` to stage a Wasm artifact without registering
67+
it in php.ini.
68+
6669
External extensions are only supported when the Node.js runtime has JSPI
6770
available. Asyncify support is limited to the bundled extensions shipped with
6871
this package.

packages/php-wasm/node/src/test/with-php-extensions.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,54 @@ describe('withPHPExtensions', () => {
105105
).rejects.toThrow('External PHP extensions require JSPI');
106106
});
107107

108+
it('stages extension artifacts without adding a php.ini scan dir', async () => {
109+
const tempDir = await mkdtemp(
110+
path.join(tmpdir(), 'php-wasm-extension-')
111+
);
112+
try {
113+
const extensionBytes = new Uint8Array([1, 2, 3]);
114+
await writeFile(
115+
path.join(tempDir, 'sqlite_markdown.so'),
116+
extensionBytes
117+
);
118+
await writeFile(
119+
path.join(tempDir, 'manifest.json'),
120+
JSON.stringify({
121+
name: 'sqlite_markdown',
122+
artifacts: [
123+
{
124+
phpVersion: '8.4',
125+
sourcePath: 'sqlite_markdown.so',
126+
},
127+
],
128+
})
129+
);
130+
131+
const options = await withPHPExtensions('8.4', 'jspi', {}, [
132+
{
133+
source: {
134+
format: 'manifest',
135+
manifestUrl: path.join(tempDir, 'manifest.json'),
136+
},
137+
loadWithIniDirective: false,
138+
},
139+
]);
140+
const fs = createFakeFS();
141+
142+
expect(options.ENV?.['PHP_INI_SCAN_DIR']).toBeUndefined();
143+
options.onRuntimeInitialized?.({ FS: fs } as any);
144+
145+
expect(
146+
fs.files.get(`${PHP_EXTENSIONS_DIR}/sqlite_markdown.so`)
147+
).toEqual(extensionBytes);
148+
expect(
149+
fs.files.has(`${PHP_EXTENSIONS_DIR}/sqlite_markdown.ini`)
150+
).toBe(false);
151+
} finally {
152+
await rm(tempDir, { recursive: true, force: true });
153+
}
154+
});
155+
108156
it('treats drive-letter-shaped strings as local paths, not URL schemes', () => {
109157
const source = normalizeNodeExtensionSource({
110158
format: 'manifest',

packages/php-wasm/universal/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ artifacts for the PHP version matrix:
2121
"artifacts": [
2222
{
2323
"phpVersion": "8.4",
24-
"file": "wp_mysql_parser-php8.4-jspi.so",
25-
"sha256": "..."
24+
"sourcePath": "wp_mysql_parser-php8.4-jspi.so"
2625
}
2726
]
2827
}
2928
```
3029

31-
`file` may be absolute, or relative to the manifest URL. If you pass an inline
32-
manifest instead of `manifestUrl`, pass `baseUrl` to choose where relative
33-
artifact files are resolved from.
30+
`sourcePath` may be absolute, or relative to the manifest URL. If you pass an
31+
inline manifest instead of `manifestUrl`, pass `baseUrl` to choose where
32+
relative artifact files are resolved from.
3433

3534
Asyncify extension loading is reserved for bundled extensions shipped with the
3635
PHP.wasm packages, such as `intl`, `xdebug`, `redis`, and `memcached`.
@@ -40,7 +39,9 @@ PHP.wasm packages, such as `intl`, `xdebug`, `redis`, and `memcached`.
4039
`resolvePHPExtension()` turns bytes, a direct artifact URL, or a manifest into a
4140
`ResolvedPHPExtension`. `withResolvedPHPExtensions()` then augments Emscripten
4241
options so the extension `.so`, generated `.ini`, sidecar files, and environment
43-
variables are ready before PHP scans its `.ini` files.
42+
variables are ready before PHP scans its `.ini` files. When
43+
`loadWithIniDirective` is `false`, the `.so` and sidecar files are still staged
44+
but no `.ini` file or `PHP_INI_SCAN_DIR` entry is generated.
4445

4546
```ts
4647
import { resolvePHPExtension, withResolvedPHPExtensions } from '@php-wasm/universal';

0 commit comments

Comments
 (0)