wordpress-playground icon indicating copy to clipboard operation
wordpress-playground copied to clipboard

[Exploration] PHP.wasm build without distinction between Node and Web

Open mho22 opened this issue 4 months ago • 6 comments

@adamziel's suggestion :

It would be cool to get rid of the node vs web distinction eventually. We could do that if Node-only extensions were shipped as dynamic extensions. Not a priority, but let's keep that in mind.

Let's keep this issue open to document what's possible and what has to be done to eventually have a unique PHP.wasm compilation environment.

Based on these lines in compile/build.js file :

web: {
	WITH_INTL: 'yes',
},
node: {
	WITH_NODEFS: 'yes',
	WITH_MYSQL: 'yes',
},

The next dynamic extension should be mysql for Node only. Since WITH_NODEFS is not used anymore.

While digging a bit deeper, I found 7 occurrences of :

if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
    // ...
fi; \

In php/Dockerfile :

  1. To add NodeFS when building for Node [ -lnodefs.js ]
  2. To preserve symbol names in NodeJS build [ -g2 ]
  3. Adding fd_close to JSPI_IMPORTS and JSPI_EXPORTS
  4. PHP.wasm file locking support [ -DPHP_WASM_FILE_LOCKING_SUPPORT ]
  5. Replacing new WebSocketServer in php.js
  6. Add __dirname declaration an create a require() function
  7. dependencyFilename path

Some can be removed [ 2 ] or improved [ 4, 5 ] while others are needed [ 1, 3 ].

While 6 and 7 could be possible manipulated within Vite or ESbuild?

And 1 occurence of :

if [ "$EMSCRIPTEN_ENVIRONMENT" = "web" ]; then \
    // ...
fi; \

In php/Dockerfile :

  1. --source-map-base

But most importantly :

-s ENVIRONMENT=$EMSCRIPTEN_ENVIRONMENT \

This implies we need to build for node and web.

cc @adamziel and @brandonpayton What do you think?

mho22 avatar Sep 16 '25 11:09 mho22