Skip to content

Expand php-wasm/node multi-worker support to Asyncify builds #2317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: trunk
Choose a base branch
from
Draft
44 changes: 37 additions & 7 deletions packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ ARG WITH_JSPI="no"
# but just "7" is invalid because there's no branch PHP-7.
ARG PHP_VERSION

# TODO: Remove or adjust this overwhelming warning setting
ENV WASM_WARNING_FLAGS=" -Weverything -fdiagnostics-show-option "

# Clone PHP
RUN git clone https://github.com/php/php-src.git php-src \
--branch PHP-$PHP_VERSION \
Expand Down Expand Up @@ -488,8 +491,11 @@ RUN source /root/emsdk/emsdk_env.sh && \
export PHP_VERSION_ESCAPED="${PHP_VERSION//./_}" && \
EMCC_FLAGS=" -D__x86_64__ -sSIDE_MODULE -Dsetsockopt=wasm_setsockopt -Dphp_exec=wasm_php_exec \
$JSPI_FLAGS \
$WASM_WARNING_FLAGS \
-fdebug-compilation-dir=${DEBUG_DWARF_COMPILATION_DIR}/ \
-fdebug-prefix-map=/root/php-src/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
-fdebug-prefix-map=/root/php-src/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ \
-fdebug-prefix-map=/emsdk/emscripten/==${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/emscripten/ \
-fdebug-prefix-map=/root/emsdk/upstream/emscripten/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/emscripten/ " \
# ...which means we must skip all the libraries - they will be provided in the final linking step.
emmake make -j1

Expand Down Expand Up @@ -523,8 +529,10 @@ RUN set -euxo pipefail; \
export PHP_VERSION_ESCAPED="${PHP_VERSION//./_}"; \
echo -n " -fdebug-compilation-dir=${DEBUG_DWARF_COMPILATION_DIR}/ " \
"-fdebug-prefix-map=/root/php_wasm.c=${DEBUG_DWARF_COMPILATION_DIR}/compile/php/php_wasm.c " \
"-fdebug-prefix-map=/root/php-src/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=./=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=/root/php-src/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=./=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=/emsdk/emscripten/==${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/emscripten/ " \
"-fdebug-prefix-map=/root/emsdk/upstream/emscripten/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/emscripten/ " \
>> /root/.emcc-php-wasm-flags; \
if [ "${WITH_SOURCEMAPS}" = "yes" ]; then \
echo -n ' -gsource-map' >> /root/.emcc-php-wasm-flags; \
Expand Down Expand Up @@ -615,11 +623,19 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"_js_popen_to_file",\n\
"_asyncjs__js_popen_to_file",\n\
"__syscall_fcntl64",\n\
"___syscall_fcntl64",\n\
"_asyncjs___syscall_fcntl64",\n\
"js_release_file_locks",\n\
"_js_release_file_locks",\n\
"_async_js_release_file_locks",\n\
"js_flock",\n\
"_js_flock",\n\
"_async_js_flock",\n\
"js_fd_read",\n\
"_js_fd_read",\n\
"fd_close",\n\
"_fd_close",\n\
"_asyncjs__fd_close",\n\
"js_module_onMessage",\n\
"_js_module_onMessage",\n\
"_asyncjs__js_module_onMessage",\n\
Expand All @@ -632,7 +648,15 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"_wasm_shutdown",\n\
"_asyncjs__wasm_shutdown"]'; \
echo -n " -s ASYNCIFY_IMPORTS=$ASYNCIFY_IMPORTS " | tr -d "\n" >> /root/.emcc-php-asyncify-flags; \
export ASYNCIFY_ONLY_UNPREFIXED=$'"__fseeko_unlocked",\
export ASYNCIFY_ONLY_UNPREFIXED=$'"null.<anonymous>",\
"__stdio_close",\
"zend_stream_stdio_closer",\
"zend_destroy_file_handle",\
"php_init_config",\
"zend_register_ini_entries_ex",\
"php_module_startup",\
"wasm_sapi_module_startup",\
"__fseeko_unlocked",\
"__ftello_unlocked",\
"__funcs_on_exit",\
"__fwritex",\
Expand Down Expand Up @@ -2062,7 +2086,7 @@ RUN set -euxo pipefail; \
export OPTIMIZATION_FLAGS="-O0"; \
fi; \
PLATFORM_SPECIFIC_ARGS=''; \
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ] && [ "$WITH_JSPI" = "yes" ]; then \
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
PLATFORM_SPECIFIC_ARGS="$PLATFORM_SPECIFIC_ARGS -DPHP_WASM_FILE_LOCKING_SUPPORT=1"; \
PLATFORM_SPECIFIC_ARGS="$PLATFORM_SPECIFIC_ARGS --js-library /root/phpwasm-emscripten-library-dynamic-linking.js"; \
PLATFORM_SPECIFIC_ARGS="$PLATFORM_SPECIFIC_ARGS --js-library /root/phpwasm-emscripten-library-file-locking-for-node.js -Wl,--wrap=getpid"; \
Expand Down Expand Up @@ -2090,6 +2114,8 @@ RUN set -euxo pipefail; \
-s INITIAL_MEMORY=1024MB \
-s ALLOW_MEMORY_GROWTH=1 \
-s ASSERTIONS=0 \
# TODO: Remove this super-high ASYNCIFY_STACK_SIZE before merge
-s ASYNCIFY_STACK_SIZE=999999 \
-s ERROR_ON_UNDEFINED_SYMBOLS=1 \
-s NODEJS_CATCH_EXIT=0 \
-s NODEJS_CATCH_REJECTION=0 \
Expand All @@ -2103,6 +2129,7 @@ RUN set -euxo pipefail; \
$(cat /root/.emcc-php-wasm-sources) \
-s ENVIRONMENT=$EMSCRIPTEN_ENVIRONMENT \
-s FORCE_FILESYSTEM=1 \
$WASM_WARNING_FLAGS \
-s EXPORT_NAME="'PHPLoader'"
# Emscripten complains it can't find some Asyncify functions
# listed in ASYNCIFY_IMPORTS. The culprit is those functions
Expand Down Expand Up @@ -2240,6 +2267,9 @@ RUN set -euxo pipefail; \
if [ "${WITH_SOURCEMAPS}" = "yes" ] || [ "${WITH_DEBUG}" = "yes" ]; then \
# Make PHP source available for use with step debugger
rm -rf /root/php-src/.git; \
cp -r /root/php-src "/root/output/${PHP_VERSION_ESCAPED}/php-src"; \
cp -r /root/emsdk/upstream/emscripten/system "/root/output/${PHP_VERSION_ESCAPED}/php-src/system"; \
cp -r /root/php-src /root/output/"${PHP_VERSION_ESCAPED}"/php-src; \
# Copy emscripten source files
mkdir -p /root/output/"${PHP_VERSION_ESCAPED}"/emscripten; \
cp -r /root/emsdk/upstream/emscripten/cache /root/output/"${PHP_VERSION_ESCAPED}"/emscripten/; \
cp -r /root/emsdk/upstream/emscripten/system /root/output/"${PHP_VERSION_ESCAPED}"/emscripten/; \
fi;
Loading
Loading