Skip to content

Commit aa72e45

Browse files
Fix php-wasm build error for WITH_SOURCEMAPS=yes (#44)
## Motivation for the change, related issues Building php-wasm with WITH_SOURCEMAPS=yes is currently broken. When WITH_SOURCEMAPS is enabled, it turns out Emscripten is generating JS that uses single quotes rather than double-quotes. I guess this has to do with the difference in optimization options but have not tested it. ## Implementation details This PR fixes the build so there is no longer an error by expanding the php-wasm JS replacement regexes to match on either single or double quotes. I have not tested actually debugging with sourcemaps, but this fixes the build error. Once this is fixed I plan add a build arg for compiling php-wasm with DWARF debug info so we [can step-through-debug the PHP runtime in Chrome](https://developer.chrome.com/docs/devtools/wasm) with access to variable values. ## Testing Instructions (or ideally a Blueprint) Run the following command on trunk and on this branch, and note that it fails on trunk and succeeds on this branch. ``` npx nx recompile-php:asyncify php-wasm-web -- --PHP_VERSION=8.4 --WITH_SOURCEMAPS=yes ```
1 parent 256f65b commit aa72e45

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/php-wasm/compile/php/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ RUN set -euxo pipefail; \
10711071
# This assumes the traffic is always forwarded to the same target.
10721072
# However, we want to support arbitrary targets, so we need to
10731073
# replace the hardcoded websocket target URL with a dynamic callback.
1074-
/root/replace.sh $'s/if\s*\(\s*SOCKFS\.websocketArgs\["url"\]\s*\)/if("function"===typeof SOCKFS.websocketArgs["url"]) {\nurl = SOCKFS.websocketArgs["url"](...arguments);\n}else if ("string" === typeof SOCKFS.websocketArgs["url"])/g' \
1074+
/root/replace.sh $'s/if\s*\(\s*SOCKFS\.websocketArgs\[[\'"]url[\'"]\]\s*\)/if("function"===typeof SOCKFS.websocketArgs["url"]) {\nurl = SOCKFS.websocketArgs["url"](...arguments);\n}else if ("string" === typeof SOCKFS.websocketArgs["url"])/g' \
10751075
/root/output/php.js; \
10761076
# Enable custom WebSocket constructors to support socket options.
10771077
/root/replace.sh "s/ws\s*=\s*new WebSocketConstructor/if (Module['websocket']['decorator']) {WebSocketConstructor = Module['websocket']['decorator'](WebSocketConstructor);}ws = new WebSocketConstructor/g" /root/output/php.js && \
@@ -1122,13 +1122,13 @@ RUN set -euxo pipefail; \
11221122
# In case of WordPress Playground, the worker in which the PHP
11231123
# runs will typically exit after the PHP program finishes, so
11241124
# we don't have to worry about memory leaks.
1125-
/root/replace-across-lines.sh 's/(class\s+ExitStatus\s*\{\s*name\s*=\s*"ExitStatus";\s*constructor\(\s*status\s*\)\s*\{\s*this\.message\s*=\s*`Program terminated with exit\(\$\{status\}\)`;\s*this.status\s*=\s*status;?\s*\}\s*\})/$1\nExitStatus = class PHPExitStatus extends Error {\nconstructor(status) {\n super(status);\n this.name = "ExitStatus";\n this.message = "Program terminated with exit(" + status + ")";\n this.status = status;\n }\n};/' /root/output/php.js; \
1125+
/root/replace-across-lines.sh "s/(class\\s+ExitStatus\\s*{\\s*name\\s*=\\s*['\"]ExitStatus['\"];\\s*constructor\\s*\(\\s*status\\s*\)\\s*{\\s*this\\.message\\s*=\\s*\`Program terminated with exit\(\\\${status}\)\`;\s*this\\.status\\s*=\\s*status;\\s*}\\s*})/\$1\nExitStatus = class PHPExitStatus extends Error {\n constructor\(status\) {\n super\(status\);\n this.name = 'ExitStatus';\n this.message = 'Program terminated with exit\(' + status + '\)';\n this.status = status;\n }\n};/" /root/output/php.js; \
11261126
# Restore quit handling to Emscripten
11271127
# Quit callback customization was removed from Emscripten by:
11281128
# https://github.com/emscripten-core/emscripten/pull/22371
11291129
# But the alternative `onExit()` handling is conditional and has different semantics.
11301130
# To avoid bugs due to this change, let's just restore support for quit callback customization.
1131-
/root/replace.sh 's/(if\s*\(Module\["thisProgram"\]\)\s*thisProgram\s*=\s*Module\["thisProgram"\];)/$1\nif (Module["quit"]) quit_=Module["quit"];/' /root/output/php.js; \
1131+
/root/replace.sh "s/(if\s*\(Module\[['\"]thisProgram['\"]\]\)\s*thisProgram\s*=\s*Module\[['\"]thisProgram['\"]\];)/\$1\nif (Module[\"quit\"]) quit_=Module[\"quit\"];/" /root/output/php.js; \
11321132
# Turn the php.js file into an ES module
11331133
# Manually turn the output into a esm module instead of relying on -s MODULARIZE=1.
11341134
# which pollutes the global namespace and does not play well with import() mechanics.

0 commit comments

Comments
 (0)