Skip to content

Commit

Permalink
JSPI: Pass all unit tests, remove stale PHP builds (#1876)
Browse files Browse the repository at this point in the history
Fixes the JSPI details overlooked in the original JSPI PR (#1867):

* Correctly define the PLAYGROUND_JSPI constant to ensure EM_ASYNC_JS is
used in JSPI builds. It wasn't picked up before.
* Provide -sJSPI_IMPORTS during the build to ensure WebAssembly waits
for any promises returned by js_open_process and other JavaScript
functions.
* Runs the CI tests using Node v23 nightly
* Solves a few small issues – look around the diff for more details

 ## Testing instructions

* CI checks should pass
* All unit tests should pass locally in Node.js v23 nightly:

```
$ node-v23.0.0-nightly2024100909d10b50dc-darwin-x64/bin/node --experimental-wasm-jspi --experimental-wasm-stack-switching --expose-gc node_modules/nx/bin/nx run php-wasm-node:test
```
  • Loading branch information
adamziel authored Oct 9, 2024
1 parent b844dc6 commit 0385459
Show file tree
Hide file tree
Showing 63 changed files with 1,763 additions and 2,605 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
submodules: true
- uses: ./.github/actions/prepare-playground
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test --configuration=ci
# JSPI doesn't seem to be supported in Node.js 22
# It used to work, see https://github.com/WordPress/wordpress-playground/pull/1339.
# These days, though, running our JSPI builds throws the following error: TypeError: WebAssembly.Suspending is not a constructor
# Most of these tests pass locally but the process is crashing
# on the CI runner.
#
# test-unit-jspi:
# runs-on: ubuntu-latest
# needs: [lint-and-typecheck]
Expand All @@ -44,7 +44,8 @@ jobs:
# submodules: true
# - uses: ./.github/actions/prepare-playground
# with:
# node-version: 22
# # @TODO: Switch to the production version once it's released
# node-version: 23.0.0-nightly2024100909d10b50dc
# - run: node --experimental-wasm-jspi --experimental-wasm-stack-switching --expose-gc node_modules/nx/bin/nx affected --target=test --configuration=ci
test-e2e:
runs-on: ubuntu-latest
Expand Down
81 changes: 40 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,47 @@
"typecheck": "nx run-many --all --target=typecheck",
"prepare": "husky install",
"recompile:php": "npm run recompile:php:web && npm run recompile:php:node",
"recompile:php:web": "nx recompile-php:all php-wasm-web",
"recompile:php:web:jspi:all": "nx recompile-php:jspi:all php-wasm-web",
"recompile:php:web:jspi:8.3": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.3",
"recompile:php:web:jspi:8.2": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.2",
"recompile:php:web:jspi:8.1": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.1",
"recompile:php:web:jspi:8.0": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.0",
"recompile:php:web:jspi:7.4": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.4",
"recompile:php:web:jspi:7.3": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.3",
"recompile:php:web:jspi:7.2": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.2",
"recompile:php:web:jspi:7.1": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.1",
"recompile:php:web:jspi:7.0": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.0",
"recompile:php:web:asyncify:all": "nx recompile-php:asyncify:all php-wasm-web",
"recompile:php:web:asyncify:8.3": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.3",
"recompile:php:web:asyncify:8.2": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.2",
"recompile:php:web:asyncify:8.1": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.1",
"recompile:php:web:asyncify:8.0": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.0",
"recompile:php:web:asyncify:7.4": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.4",
"recompile:php:web:asyncify:7.3": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.3",
"recompile:php:web:asyncify:7.2": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.2",
"recompile:php:web:asyncify:7.1": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.1",
"recompile:php:web:asyncify:7.0": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.0",
"recompile:php:node": "nx recompile-php:all php-wasm-node",
"recompile:php:node:jspi:all": "nx recompile-php:jspi:all php-wasm-node",
"recompile:php:node:jspi:8.3": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.3",
"recompile:php:node:jspi:8.2": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.2",
"recompile:php:node:jspi:8.1": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.1",
"recompile:php:node:jspi:8.0": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.0",
"recompile:php:node:jspi:7.4": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.4",
"recompile:php:node:jspi:7.3": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.3",
"recompile:php:node:jspi:7.2": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.2",
"recompile:php:node:jspi:7.1": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.1",
"recompile:php:node:jspi:7.0": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.0",
"recompile:php:node:asyncify:all": "nx recompile-php:asyncify:all php-wasm-node",
"recompile:php:node:asyncify:8.3": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.3",
"recompile:php:node:asyncify:8.2": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.2",
"recompile:php:node:asyncify:8.1": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.1",
"recompile:php:node:asyncify:8.0": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.0",
"recompile:php:node:asyncify:7.4": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.4",
"recompile:php:node:asyncify:7.3": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.3",
"recompile:php:node:asyncify:7.2": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.2",
"recompile:php:node:asyncify:7.1": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.1",
"recompile:php:node:asyncify:7.0": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.0"
"recompile:php:web:jspi:8.3": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.3 ",
"recompile:php:web:jspi:8.2": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.2 ",
"recompile:php:web:jspi:8.1": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.1 ",
"recompile:php:web:jspi:8.0": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=8.0 ",
"recompile:php:web:jspi:7.4": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.4 ",
"recompile:php:web:jspi:7.3": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.3 ",
"recompile:php:web:jspi:7.2": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.2 ",
"recompile:php:web:jspi:7.1": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.1 ",
"recompile:php:web:jspi:7.0": "nx recompile-php:jspi php-wasm-web -- --PHP_VERSION=7.0 ",
"recompile:php:web:asyncify:all": "nx recompile-php:asyncify php-wasm-web",
"recompile:php:web:asyncify:8.3": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.3 ",
"recompile:php:web:asyncify:8.2": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.2 ",
"recompile:php:web:asyncify:8.1": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.1 ",
"recompile:php:web:asyncify:8.0": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.0 ",
"recompile:php:web:asyncify:7.4": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.4 ",
"recompile:php:web:asyncify:7.3": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.3 ",
"recompile:php:web:asyncify:7.2": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.2 ",
"recompile:php:web:asyncify:7.1": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.1 ",
"recompile:php:web:asyncify:7.0": "nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=7.0 ",
"recompile:php:node": "nx recompile-php:all php-wasm-node ",
"recompile:php:node:jspi:all": "nx recompile-php:jspi:all php-wasm-node ",
"recompile:php:node:jspi:8.3": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.3 ",
"recompile:php:node:jspi:8.2": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.2 ",
"recompile:php:node:jspi:8.1": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.1 ",
"recompile:php:node:jspi:8.0": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=8.0 ",
"recompile:php:node:jspi:7.4": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.4 ",
"recompile:php:node:jspi:7.3": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.3 ",
"recompile:php:node:jspi:7.2": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.2 ",
"recompile:php:node:jspi:7.1": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.1 ",
"recompile:php:node:jspi:7.0": "nx recompile-php:jspi php-wasm-node -- --PHP_VERSION=7.0 ",
"recompile:php:node:asyncify:all": "nx recompile-php:asyncify:all php-wasm-node ",
"recompile:php:node:asyncify:8.3": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.3 ",
"recompile:php:node:asyncify:8.2": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.2 ",
"recompile:php:node:asyncify:8.1": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.1 ",
"recompile:php:node:asyncify:8.0": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=8.0 ",
"recompile:php:node:asyncify:7.4": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.4 ",
"recompile:php:node:asyncify:7.3": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.3 ",
"recompile:php:node:asyncify:7.2": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.2 ",
"recompile:php:node:asyncify:7.1": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.1 ",
"recompile:php:node:asyncify:7.0": "nx recompile-php:asyncify php-wasm-node -- --PHP_VERSION=7.0 "
},
"private": true,
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,11 @@ RUN set -euxo pipefail; \
mkdir -p /build/output; \
source /root/emsdk/emsdk_env.sh; \
if [ "$WITH_JSPI" = "yes" ]; then \
export ASYNCIFY_FLAGS=" -dPLAYGROUND_JSPI -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_EXPORTS=wasm_sleep,wasm_read,emscripten_sleep,wasm_sapi_handle_request,wasm_sapi_request_shutdown,wasm_poll_socket,wrap_select,__wrap_select,select,php_pollfd_for,fflush,wasm_popen,wasm_read,wasm_php_exec,run_cli -s EXTRA_EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports,_malloc "; \
export ASYNCIFY_FLAGS=" -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_IMPORTS=js_open_process,js_waitpid,js_process_status,js_create_input_device,wasm_setsockopt,wasm_shutdown,wasm_close -sJSPI_EXPORTS=wasm_sleep,wasm_read,emscripten_sleep,wasm_sapi_handle_request,wasm_sapi_request_shutdown,wasm_poll_socket,wrap_select,__wrap_select,select,php_pollfd_for,fflush,wasm_popen,wasm_read,wasm_php_exec,run_cli -s EXTRA_EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports,_malloc "; \
echo '#define PLAYGROUND_JSPI 1' > /root/php_wasm_asyncify.h; \
else \
export ASYNCIFY_FLAGS=" -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 -s EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports $(cat /root/.emcc-php-asyncify-flags) "; \
echo '' > /root/php_wasm_asyncify.h; \
fi; \
export EXPORTED_FUNCTIONS=$'["_exit", \n\
"UTF8ToString", \n\
Expand Down
3 changes: 3 additions & 0 deletions packages/php-wasm/compile/php/php_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "proc_open.h"
#include "dns_polyfill.h"

// Created by Dockerfile:
#include "php_wasm_asyncify.h"

unsigned int wasm_sleep(unsigned int time)
{
emscripten_sleep(time * 1000); // emscripten_sleep takes time in milliseconds
Expand Down
Loading

0 comments on commit 0385459

Please sign in to comment.