Skip to content

Commit 10a2626

Browse files
committed
Reconcile some trunk changes
1 parent c37dc2d commit 10a2626

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

packages/php-wasm/compile/Dockerfile

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ FROM emscripten AS emscripten-libzip
103103
ARG PHP_VERSION
104104
COPY --from=emscripten-libz /root/lib /root/lib-libz
105105
RUN /root/copy-lib.sh lib-libz
106-
RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]] || [ "${PHP_VERSION:0:1}" -le "5" ]; then \
106+
RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then \
107107
export LIBZIP_VERSION=1.2.0; \
108108
else \
109109
export LIBZIP_VERSION=1.9.2; \
@@ -274,10 +274,7 @@ COPY --from=emscripten-libzip /root/lib /root/lib-libzip
274274
RUN if [ "$WITH_LIBZIP" = "yes" ]; then \
275275
/root/copy-lib.sh lib-libz; \
276276
/root/copy-lib.sh lib-libzip && \
277-
if [ "${PHP_VERSION:0:1}" -le "5" ]; then \
278-
/root/replace.sh 's/ZEND_MODULE_GLOBALS_CTOR_N/(void (*)(void *))ZEND_MODULE_GLOBALS_CTOR_N/g' /root/php-src/ext/zlib/zlib.c; \
279-
fi;\
280-
if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]] || [ "${PHP_VERSION:0:1}" -le "5" ]; then \
277+
if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then \
281278
apt install -y zlib1g zlib1g-dev; \
282279
# https://php-legacy-docs.zend.com/manual/php5/en/zlib.installation
283280
echo -n ' --with-zlib --with-zlib-dir=/root/lib --enable-zip --with-libzip=/root/lib ' >> /root/.php-configure-flags-bundled-extensions; \
@@ -323,7 +320,7 @@ RUN if [ "$WITH_LIBXML" = "yes" ]; \
323320
# In the regular cc it's just a warning, but in the emscripten's emcc that's an error:
324321
perl -pi.bak -e 's/char xmlInitParser/void xmlInitParser/g' /root/php-src/configure; \
325322
# On PHP < 7.1.0, the dom_iterators.c file implicitly converts *char to const *char causing emcc error
326-
if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "0" ]] || [ "${PHP_VERSION:0:1}" -le "5" ]; then \
323+
if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "0" ]]; then \
327324
/root/replace.sh 's/xmlHashScan\(ht, itemHashScanner, iter\);/xmlHashScan(ht, (xmlHashScanner)itemHashScanner, iter);/g' /root/php-src/ext/dom/dom_iterators.c; \
328325
fi; \
329326
else \
@@ -369,7 +366,7 @@ RUN if [ "$WITH_ICONV" = "yes" ]; \
369366
# PHP <= 7.3 requires Bison 2.7
370367
# PHP >= 7.4 and Bison 3.0
371368
COPY --from=emscripten-bison-2-7 /usr/local/bison /root/linked-bison-27
372-
RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]] || [ "${PHP_VERSION:0:1}" -le "5" ]; then \
369+
RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then \
373370
mv /root/linked-bison-27 /usr/local/bison && \
374371
ln -s /usr/local/bison/bin/bison /usr/bin/bison && \
375372
ln -s /usr/local/bison/bin/yacc /usr/bin/yacc; \
@@ -497,7 +494,7 @@ RUN /root/replace.sh 's/define HAVE_UNISTD_H 1/define HAVE_UNISTD_H 0/g' /root/p
497494

498495
# PHP <= 7.3 is not very good at detecting the presence of the POSIX readdir_r function
499496
# so we need to force it to be enabled.
500-
RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]] || [ "${PHP_VERSION:0:1}" -le "5" ]; then \
497+
RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then \
501498
echo '#define HAVE_POSIX_READDIR_R 1' >> /root/php-src/main/php_config.h; \
502499
fi;
503500

@@ -508,12 +505,28 @@ RUN /root/replace.sh 's/static int php_cli_server_poller_poll/extern int wasm_se
508505
# Provide a custom implementation of the php_select() function.
509506
RUN /root/replace.sh 's/return php_select\(/return wasm_select(/g' /root/php-src/sapi/cli/php_cli_server.c
510507

508+
# Provide a custom implementation of the php_exec() function that handles spawning
509+
# the process inside exec(), passthru(), system(), etc.
510+
# We effectively remove the php_exec() implementation from the build by renaming it
511+
# to an unused identifier "php_exec_old", and then we mark php_exec as extern.
512+
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
513+
514+
# Provide a custom implementation of the VCWD_POPEN() function that handles spawning
515+
# the process inside PHP_FUNCTION(popen).
516+
RUN /root/replace.sh 's/VCWD_POPEN\(/wasm_popen(/g' /root/php-src/ext/standard/file.c
517+
RUN /root/replace.sh 's/PHP_FUNCTION\(popen\)/extern FILE *wasm_popen(const char *cmd, const char *mode);PHP_FUNCTION(popen)/g' /root/php-src/ext/standard/file.c
518+
511519
# Provide a custom implementation of the shutdown() function.
512520
RUN perl -pi.bak -e $'s/(\s+)shutdown\(/$1 wasm_shutdown(/g' /root/php-src/sapi/cli/php_cli_server.c
513521
RUN perl -pi.bak -e $'s/(\s+)closesocket\(/$1 wasm_close(/g' /root/php-src/sapi/cli/php_cli_server.c
514522
RUN echo 'extern int wasm_shutdown(int fd, int how);' >> /root/php-src/main/php_config.h;
515523
RUN echo 'extern int wasm_close(int fd);' >> /root/php-src/main/php_config.h;
516524

525+
# Don't ship PHP_FUNCTION(proc_open) with the PHP build
526+
# so that we can ship a patched version with php_wasm.c
527+
RUN echo '' > /root/php-src/ext/standard/proc_open.h;
528+
RUN echo '' > /root/php-src/ext/standard/proc_open.c;
529+
517530
RUN source /root/emsdk/emsdk_env.sh && \
518531
# We're compiling PHP as emscripten's side module...
519532
EMCC_FLAGS=" -sSIDE_MODULE -Dsetsockopt=wasm_setsockopt -Dpopen=wasm_popen -Dpclose=wasm_pclose " \
@@ -525,6 +538,16 @@ RUN cp -v /root/php-src/.libs/libphp*.la /root/lib/libphp.la
525538
RUN cp -v /root/php-src/.libs/libphp*.a /root/lib/libphp.a
526539

527540
COPY ./build-assets/php_wasm.c /root/
541+
COPY ./build-assets/proc_open* /root/
542+
543+
RUN if [[ "${PHP_VERSION:0:1}" -le "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then \
544+
cp /root/proc_open7.0.c /root/proc_open.c; \
545+
cp /root/proc_open7.0.h /root/proc_open.h; \
546+
else \
547+
cp /root/proc_open7.4.c /root/proc_open.c; \
548+
cp /root/proc_open7.4.h /root/proc_open.h; \
549+
fi
550+
528551

529552
ARG WITH_SOURCEMAPS
530553
RUN set -euxo pipefail; \
@@ -605,7 +628,10 @@ RUN if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; \
605628
"invoke_viiiiii",\n\
606629
"invoke_viiiiiii",\n\
607630
"invoke_viiiiiiiii",\n\
631+
"js_open_process",\n\
632+
"js_popen_to_file",\n\
608633
"wasm_poll_socket",\n\
634+
"js_module_onMessage",\n\
609635
"wasm_shutdown"]'; \
610636
echo -n " -s ASYNCIFY_IMPORTS=$ASYNCIFY_IMPORTS " | tr -d "\n" >> /root/.emcc-php-wasm-flags; \
611637
export ASYNCIFY_ONLY_UNPREFIXED=$'"dynCall_dd",\
@@ -639,7 +665,14 @@ RUN if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; \
639665
"dynCall_viiiii",\
640666
"dynCall_viiiiiii",\
641667
"dynCall_viiiiiiii",'; \
642-
export ASYNCIFY_ONLY=$'"zif_array_filter",\
668+
export ASYNCIFY_ONLY=$'"zif_array_filter",\"__fwritex",\
669+
"zif_sleep",\
670+
"zif_stream_get_contents",\
671+
"php_stdiop_read",\
672+
"fwrite",\
673+
"zif_fwrite",\
674+
"php_stdiop_write",\
675+
"zif_array_filter",\
643676
"dlopen",\
644677
"zend_load_extension",\
645678
"zend_call_known_instance_method_with_2_params",\
@@ -697,6 +730,8 @@ RUN if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; \
697730
"ZEND_ISSET_ISEMPTY_PROP_OBJ_SPEC_TMPVAR_CONST_HANDLER",\
698731
"ZEND_ISSET_ISEMPTY_PROP_OBJ_SPEC_TMPVAR_HANDLER",\
699732
"cli",\
733+
"wasm_sleep",\
734+
"wasm_php_exec",\
700735
"wasm_sapi_handle_request",\
701736
"_call_user_function_ex",\
702737
"_call_user_function_impl",\
@@ -782,6 +817,7 @@ RUN if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; \
782817
"php_cli_server_do_event_for_each_fd_callback",\
783818
"php_cli_server_poller_poll",\
784819
"php_cli_server_recv_event_read_request",\
820+
"php_exec",\
785821
"php_execute_script",\
786822
"php_fsockopen_stream",\
787823
"php_getimagesize_from_any",\
@@ -880,6 +916,7 @@ RUN if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; \
880916
"zif_fclose",\
881917
"zif_feof",\
882918
"zif_file_get_contents",\
919+
"zif_post_message_to_js",\
883920
"zif_fopen",\
884921
"zif_fread",\
885922
"zif_fsockopen",\
@@ -904,6 +941,15 @@ RUN if [ "$WITH_WS_NETWORKING_PROXY" = "yes" ]; \
904941
"zif_mysqli_stmt_execute",\
905942
"zif_mysqli_stmt_fetch",\
906943
"zif_preg_replace_callback",\
944+
"zif_popen",\
945+
"php_exec_ex",\
946+
"wasm_popen",\
947+
"zif_wasm_popen",\
948+
"zif_system",\
949+
"zif_exec",\
950+
"zif_passthru",\
951+
"zif_shell_exec",\
952+
"zif_proc_open",\
907953
"zif_stream_socket_client",\
908954
"zim_PDOStatement_execute",\
909955
"zim_PDO___construct",\
@@ -959,6 +1005,8 @@ RUN set -euxo pipefail; \
9591005
"_phpwasm_destroy_uploaded_files_hash", \n\
9601006
"_phpwasm_init_uploaded_files_hash", \n\
9611007
"_phpwasm_register_uploaded_file", \n\
1008+
"_emscripten_sleep", \n\
1009+
"_wasm_sleep", \n\
9621010
"_wasm_set_phpini_path", \n\
9631011
"_wasm_set_phpini_entries", \n\
9641012
"_wasm_add_SERVER_entry", \n\

0 commit comments

Comments
 (0)