[Exploration] PHP.wasm build without distinction between Node and Web
@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 :
- To add NodeFS when building for Node [ -lnodefs.js ]
- To preserve symbol names in NodeJS build [ -g2 ]
- Adding fd_close to JSPI_IMPORTS and JSPI_EXPORTS
- PHP.wasm file locking support [ -DPHP_WASM_FILE_LOCKING_SUPPORT ]
- Replacing new WebSocketServer in php.js
- Add __dirname declaration an create a require() function
- 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 :
- --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?