@@ -332,29 +332,12 @@ RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then
332
332
echo '#define HAVE_POSIX_READDIR_R 1' >> /root/php-src/main/php_config.h; \
333
333
fi;
334
334
335
- # Rename the original php_pollfd_for() implementation so that we can link our own version.
336
- RUN /root/replace.sh 's/static inline int php_pollfd_for\( /int php_pollfd_for(php_socket_t fd, int events, struct timeval *timeouttv); static inline int __real_php_pollfd_for(/g' /root/php-src/main/php_network.h
337
-
338
- RUN echo 'extern ssize_t wasm_read(int fd, void *buf, size_t count);' >> /root/php-src/main/php.h;
339
- RUN /root/replace.sh 's/ret = read/ret = wasm_read/g' /root/php-src/main/streams/plain_wrapper.c
340
-
341
335
# Provide a custom implementation of the php_exec() function that handles spawning
342
336
# the process inside exec(), passthru(), system(), etc.
343
337
# We effectively remove the php_exec() implementation from the build by renaming it
344
338
# to an unused identifier "php_exec_old", and then we mark php_exec as extern.
345
339
RUN /root/replace.sh 's/PHPAPI int php_exec(.+)$/PHPAPI extern int php_exec\1 ; int php_exec_old\1 /g' /root/php-src/ext/standard/exec.c
346
340
347
- # Provide a custom implementation of the VCWD_POPEN() function that handles spawning
348
- # the process inside PHP_FUNCTION(popen).
349
- RUN /root/replace.sh 's/#define VCWD_POPEN.+/#define VCWD_POPEN(command, type) wasm_popen(command,type)/g' /root/php-src/Zend/zend_virtual_cwd.h
350
- RUN echo 'extern FILE *wasm_popen(const char *cmd, const char *mode);' >> /root/php-src/Zend/zend_virtual_cwd.h
351
-
352
- # Provide a custom implementation of the shutdown() function.
353
- RUN perl -pi.bak -e $'s/(\s +)shutdown\( /$1 wasm_shutdown(/g' /root/php-src/sapi/cli/php_cli_server.c
354
- RUN perl -pi.bak -e $'s/(\s +)closesocket\( /$1 wasm_close(/g' /root/php-src/sapi/cli/php_cli_server.c
355
- RUN echo 'extern int wasm_shutdown(int fd, int how);' >> /root/php-src/main/php_config.h;
356
- RUN echo 'extern int wasm_close(int fd);' >> /root/php-src/main/php_config.h;
357
-
358
341
# Don't ship PHP_FUNCTION(proc_open) with the PHP build
359
342
# so that we can ship a patched version with php_wasm.c
360
343
RUN echo '' > /root/php-src/ext/standard/proc_open.h;
@@ -363,7 +346,7 @@ RUN echo '' > /root/php-src/ext/standard/proc_open.c;
363
346
RUN source /root/emsdk/emsdk_env.sh && \
364
347
# We're compiling PHP as emscripten's side module...
365
348
export JSPI_FLAGS=$(if [ "$WITH_JSPI" = "yes" ]; then echo "-sSUPPORT_LONGJMP=wasm -fwasm-exceptions" ; else echo "" ; fi) && \
366
- EMCC_FLAGS=" -sSIDE_MODULE -Dsetsockopt=wasm_setsockopt - Dphp_exec=wasm_php_exec $JSPI_FLAGS " \
349
+ EMCC_FLAGS=" -sSIDE_MODULE -Dphp_exec=wasm_php_exec $JSPI_FLAGS " \
367
350
# ...which means we must skip all the libraries - they will be provided in the final linking step.
368
351
EMCC_SKIP="-lz -ledit -ldl -lncurses -lzip -lpng16 -lssl -lcrypto -lxml2 -lc -lm -lsqlite3 /root/lib/lib/libxml2.a /root/lib/lib/libsqlite3.so /root/lib/lib/libsqlite3.a /root/lib/lib/libsqlite3.a /root/lib/lib/libpng16.so /root/lib/lib/libwebp.a /root/lib/lib/libjpeg.a" \
369
352
emmake make -j1
@@ -927,7 +910,7 @@ RUN set -euxo pipefail; \
927
910
mkdir -p /build/output; \
928
911
source /root/emsdk/emsdk_env.sh; \
929
912
if [ "$WITH_JSPI" = "yes" ]; then \
930
- 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 " ; \
913
+ export ASYNCIFY_FLAGS=" -sWASMFS -DWASMFS_SETUP -lopfs.js - 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=php_wasm_init, 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,wasmExports,_malloc " ; \
931
914
echo '#define PLAYGROUND_JSPI 1' > /root/php_wasm_asyncify.h; \
932
915
else \
933
916
export ASYNCIFY_FLAGS=" -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 -s EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports $(cat /root/.emcc-php-asyncify-flags) " ; \
@@ -939,6 +922,7 @@ RUN set -euxo pipefail; \
939
922
"lengthBytesUTF8", \n \
940
923
"FS", \n \
941
924
"___wrap_select", \n \
925
+ "_emscripten_stack_get_current", \n \
942
926
"_wasm_set_sapi_name", \n \
943
927
"_php_wasm_init", \n \
944
928
"_emscripten_sleep", \n \
@@ -975,7 +959,6 @@ RUN set -euxo pipefail; \
975
959
-I TSRM/ \
976
960
-I /root/lib/include \
977
961
-L/root/lib -L/root/lib/lib/ \
978
- -lproxyfs.js \
979
962
$ASYNCIFY_FLAGS \
980
963
$(cat /root/.emcc-php-wasm-flags) \
981
964
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" \
@@ -1034,21 +1017,21 @@ RUN set -euxo pipefail; \
1034
1017
# Emscripten produces an if that checks a stream.stream_ops.poll property. However,
1035
1018
# stream.stream_ops is sometimes undefined and the check fails. Let's adjust it to
1036
1019
# tolerate a null stream.stream_ops value.
1037
- /root/replace.sh "s/if\s *\( stream\. stream_ops\. poll\) /if (stream.stream_ops?.poll)/g" /root/output/php.js; \
1020
+ # /root/replace.sh "s/if\s*\(stream\.stream_ops\.poll\)/if (stream.stream_ops?.poll)/g" /root/output/php.js; \
1038
1021
# Make Emscripten websockets configurable
1039
1022
# Emscripten makes the Websocket proxy connect to a fixed URL.
1040
1023
# This assumes the traffic is always forwarded to the same target.
1041
1024
# However, we want to support arbitrary targets, so we need to
1042
1025
# replace the hardcoded websocket target URL with a dynamic callback.
1043
- /root/replace.sh $'s/if\s *\(\s *["\' ]string["\' ]\s *===\s *typeof Module\[ ["\' ]websocket["\' ]\]\[ ["\' ]url["\' ]\]\s *\) /if("function"===typeof Module["websocket"]["url"]) {\n url = Module["websocket"]["url"](...arguments);\n }else if ("string" === typeof Module["websocket"]["url"])/g' \
1044
- /root/output/php.js; \
1026
+ # /root/replace.sh $'s/if\s*\(\s*["\']string["\']\s*===\s*typeof Module\[["\']websocket["\']\]\[["\']url["\']\]\s*\)/if("function"===typeof Module["websocket"]["url"]) {\nurl = Module["websocket"]["url"](...arguments);\n}else if ("string" === typeof Module["websocket"]["url"])/g' \
1027
+ # /root/output/php.js; \
1045
1028
# Enable custom WebSocket constructors to support socket options.
1046
- /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 && \
1047
- if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
1048
- if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; then \
1049
- /root/replace.sh "s/sock\. server\s *=\s *new WebSocketServer/if (Module['websocket']['serverDecorator']) {WebSocketServer = Module['websocket']['serverDecorator'](WebSocketServer);}sock.server = new WebSocketServer/g" /root/output/php.js; \
1050
- fi; \
1051
- fi; \
1029
+ # /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 && \
1030
+ # if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
1031
+ # if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; then \
1032
+ # /root/replace.sh "s/sock\.server\s*=\s*new WebSocketServer/if (Module['websocket']['serverDecorator']) {WebSocketServer = Module['websocket']['serverDecorator'](WebSocketServer);}sock.server = new WebSocketServer/g" /root/output/php.js; \
1033
+ # fi; \
1034
+ # fi; \
1052
1035
# Add MSG_PEEK flag support in recvfrom
1053
1036
#
1054
1037
# Emscripten ignores the flags argument to ___syscall_recvfrom.
@@ -1060,11 +1043,11 @@ RUN set -euxo pipefail; \
1060
1043
# reading the remaining "TTP/1.1 200 OK" and not recognizing it as a valid
1061
1044
# status line.
1062
1045
# We need to patch the syscall to support the MSG_PEEK flag.
1063
- if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; then \
1064
- /root/replace.sh 's/sock\. sock_ops\. recvmsg\( sock,\s *len\) ;/sock.sock_ops.recvmsg(sock, len, typeof flags !== "undefined" ? flags : 0);/g' /root/output/php.js; \
1065
- /root/replace.sh 's/recvmsg\( sock,\s *length\)\s *{/recvmsg(sock, length, flags) {/g' /root/output/php.js; \
1066
- /root/replace.sh 's/if\s *\( sock\. type\s *===\s *1\s *&&\s *bytesRead\s *<\s *queuedLength\) /if (flags&2) {bytesRead = 0;} if (sock.type === 1 && bytesRead < queuedLength)/g' /root/output/php.js; \
1067
- fi ; \
1046
+ # if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; then \
1047
+ # /root/replace.sh 's/sock\.sock_ops\.recvmsg\(sock,\s*len\);/sock.sock_ops.recvmsg(sock, len, typeof flags !== "undefined" ? flags : 0);/g' /root/output/php.js; \
1048
+ # /root/replace.sh 's/recvmsg\(sock,\s*length\)\s*{/recvmsg(sock, length, flags) {/g' /root/output/php.js; \
1049
+ # /root/replace.sh 's/if\s*\(sock\.type\s*===\s*1\s*&&\s*bytesRead\s*<\s*queuedLength\)/if (flags&2) {bytesRead = 0;} if (sock.type === 1 && bytesRead < queuedLength)/g' /root/output/php.js; \
1050
+ # fi ; \
1068
1051
# Replace the hardcoded ENVIRONMENT variable with a dynamic computation
1069
1052
#
1070
1053
# The JavaScript code of the web loader and web worker loader is identical,
0 commit comments