-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PHP] Use JSPI when available, fall back to Asyncify (#1867)
## Motivation Ships every PHP.wasm build and dependency in two versions: JSPI, Asyncify. Updates `@php-wasm/web` and `@php-wasm/node` to use the JSPI version when the current runtime supports it, and and fall back to Asyncify otherwise. Why use JSPI? See #134. Tl;dr it will make PHP.wasm a whole lot more reliable. ## Implementation details This builds on top of the explorations done in #1339 – check the description and discussion there for the full "getting there" journey and detailed learnings. ### @php-wasm/compile The main Makefile ships an `_asyncify` and a `_jspi` version of every build task. Libraries, such as `libcurl` and `libedit`, store now each ship an Asyncify build and a JSPI build. Every JSPI build uses `-sSUPPORT_LONGJMP=wasm -fwasm-exceptions` flags. Asyncify builds are the same as before this PR and don't use those flags. ### @php-wasm/web and @php-wasm/node * PHP builds are shipped in `jspi` and `asyncify` subdirectories. * Emscripten doesn't export `free()` when using JSPI so we're exporting our own `wasm_free()` function. * `getPHPLoaderModule()` uses [wasm-feature-detect](https://github.com/GoogleChromeLabs/wasm-feature-detect) to check for JSPI support and load the right build. * Asynchronous JavaScript functions were moved from `phpwasm-emscripten-library.js` to `php_wasm.c` using the `EM_ASYNC_JS` macro for JSPI builds and `EM_JS` macro for Asyncify builds. * Unit tests are now ran separately on JSPI and Asyncify builds. ## Runtime support as of Oct 10th, 2024 JSPI is supported in: - ✅ Google Chrome with `#enable-experimental-webassembly-jspi` enabled at `chrome://flags`, or with sites where the JSPI origin trial is enabled. playground.wordpress.net is enrolled in the origin trial. - ✅ Node.js v22+ with `--experimental-wasm-stack-switching` feature flag. - ✅ Deno, with `--v8-flags=--experimental-wasm-jspi` feature flag - ✅ [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1850627) - ? Chrome-based browsers like Edge - ❌ Safari - ❌ Non-Chrome, non-Firefox web browsers - ❌ Node.js <= 21 - ❌ Non-v8 JS runtimes like Bun ## Testing instructions The E2E tests are a great source of insights: * Chrome supports JSPI * Firefox supports JSPI but has a separate implementation * Safari doesn't support JSPI and will use the Asyncify build We should also run the unit tests in Node v20 and v23 using with the experimental JSPI support flag.
- Loading branch information
Showing
660 changed files
with
155,676 additions
and
3,728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.