@@ -45,6 +45,7 @@ ARG WITH_SQLITE
4545ARG WITH_MYSQL
4646ARG WITH_OPENSSL
4747ARG WITH_ICONV
48+ ARG WITH_READLINE
4849ARG WITH_SOURCEMAPS
4950ARG WITH_WS_NETWORKING_PROXY
5051
@@ -93,22 +94,28 @@ RUN if [ "$WITH_LIBZIP" = "yes" ]; then \
9394 fi;
9495
9596
96- # Add ncurses if needed and libedit if needed
9797RUN if [ "$WITH_CLI_SAPI" = "yes" ]; \
9898 then \
9999 # Configure build flags
100- echo -n ' --enable-phar --enable-cli=static --enable-readline --with-libedit=/root/lib ' >> /root/.php-configure-flags && \
100+ echo -n ' --enable-phar --enable-cli=static ' >> /root/.php-configure-flags && \
101101 echo -n ' sapi/cli/php_cli_process_title.c sapi/cli/ps_title.c sapi/cli/php_http_parser.c sapi/cli/php_cli_server.c sapi/cli/php_cli.c ' \
102102 >> /root/.emcc-php-wasm-sources && \
103103 echo -n ', "_run_cli", "_wasm_add_cli_arg"' >> /root/.EXPORTED_FUNCTIONS && \
104- echo -n ' -DWITH_CLI_SAPI=1 -lncurses -ledit ' >> /root/.emcc-php-wasm-flags && \
105- # Disable dlopen() in the readline PHP extension
106- echo '#undef COMPILE_DL_READLINE' >> /root/php-src/main/php_config.h && \
107- /root/replace.sh 's/GET_SHELL_CB\( cb\) ;/(cb) = php_cli_get_shell_callbacks();/g' /root/php-src/ext/readline/readline_cli.c; \
104+ echo -n ' -DWITH_CLI_SAPI=1 ' >> /root/.emcc-php-wasm-flags; \
108105 else \
109106 echo -n ' --disable-cli ' >> /root/.php-configure-flags; \
110107 fi;
111108
109+ # Add ncurses if needed and libedit if needed
110+ RUN if [ "$WITH_READLINE" = "yes" ]; \
111+ then \
112+ echo -n ' --enable-readline --with-libedit=/root/lib ' >> /root/.php-configure-flags && \
113+ echo -n ' -lncurses -ledit ' >> /root/.emcc-php-wasm-flags && \
114+ # Disable dlopen() in the readline PHP extension
115+ /root/replace.sh 's/GET_SHELL_CB\( cb\) ;/(cb) = php_cli_get_shell_callbacks();/g' /root/php-src/ext/readline/readline_cli.c; \
116+ echo '#undef COMPILE_DL_READLINE' >> /root/php-src/main/php_config.h; \
117+ fi;
118+
112119# Add Libxml2 if needed
113120RUN if [ "$WITH_LIBXML" = "yes" ]; \
114121 then \
@@ -202,6 +209,9 @@ RUN if [ "$WITH_MYSQL" = "yes" ]; then \
202209 echo -n ' --enable-mysql --enable-pdo --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd ' >> /root/.php-configure-flags; \
203210 fi
204211
212+ # @TODO: Figure out why this is needed:
213+ RUN sed -i 's/HARDCODED_INI/HARDCODED_INI2/g' /root/php-src/sapi/cli/php_cli.c
214+
205215# Build the patched PHP
206216WORKDIR /root/php-src
207217RUN source /root/emsdk/emsdk_env.sh && \
@@ -225,7 +235,7 @@ RUN source /root/emsdk/emsdk_env.sh && \
225235 --disable-all \
226236 --enable-hash \
227237 --enable-static=yes \
228- --enable-shared=no \
238+ --enable-shared=yes \
229239 --enable-session \
230240 --enable-filter \
231241 --enable-calendar \
@@ -434,6 +444,11 @@ RUN echo -n ' -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 ' >> /root/.emcc-php-w
434444"zif_fwrite",\
435445"php_stdiop_write",\
436446"zif_array_filter",\
447+ "dlopen",\
448+ "zend_load_extension",\
449+ "zend_llist_apply",\
450+ "php_ini_register_extensions",\
451+ "php_load_zend_extension_cb",\
437452"zend_call_known_instance_method_with_2_params",\
438453"zend_fetch_dimension_address_read_R",\
439454"_zval_dtor_func_for_ptr",\
@@ -739,6 +754,7 @@ RUN set -euxo pipefail; \
739754 mkdir -p /build/output; \
740755 source /root/emsdk/emsdk_env.sh; \
741756 export EXPORTED_FUNCTIONS=$'["_exit", \n \
757+ "_compiler_globals", \n \
742758"_php_wasm_init", \n \
743759"_phpwasm_destroy_uploaded_files_hash", \n \
744760"_phpwasm_init_uploaded_files_hash", \n \
@@ -783,6 +799,7 @@ RUN set -euxo pipefail; \
783799 -s INITIAL_MEMORY=1024MB \
784800 -s ALLOW_MEMORY_GROWTH=1 \
785801 -s ASSERTIONS=0 \
802+ -s MAIN_MODULE \
786803 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \
787804 -s NODEJS_CATCH_EXIT=0 \
788805 -s NODEJS_CATCH_REJECTION=0 \
@@ -876,6 +893,8 @@ RUN set -euxo pipefail; \
876893 # wrapper function.
877894 /root/replace.sh $'s/ENVIRONMENT_IS_([A-Z]+)\s *=\s *(true|false)/ENVIRONMENT_IS_$1=RuntimeName==="$1"/g' /root/output/php.js; \
878895 /root/replace.sh 's/var ENV\s *=\s *\{ /var ENV = PHPLoader.ENV || {/g' /root/output/php.js; \
896+ /root/replace.sh 's/__dlopen_js\. /__dlopen_js_unused./g' /root/output/php.js; \
897+ /root/replace.sh 's/__dlopen_js\s *=/__dlopen_js_unused =/g' /root/output/php.js; \
879898 # Turn the php.js file into an ES module
880899 # Manually turn the output into a esm module instead of relying on -s MODULARIZE=1.
881900 # which pollutes the global namespace and does not play well with import() mechanics.
0 commit comments