Skip to content
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: XDebug support via dlopen #831

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .libs/xdebug.la
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# xdebug.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.492 2008/01/30 06:40:56)
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='xdebug.so'

# Names of this library.
library_names='xdebug.so xdebug.so xdebug.so'

# The name of the static archive.
old_library=''

# Libraries that this one depends upon.
dependency_libs=' -lm'

# Version information for xdebug.
current=0
age=0
revision=0

# Is this an already installed library?
installed=no

# Should we warn about portability when linking against -modules?
shouldnotlink=yes

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/Users/cloudnik/www/Automattic/core/xdebug/modules'
35 changes: 35 additions & 0 deletions .libs/xdebug.lai
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# xdebug.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.492 2008/01/30 06:40:56)
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='xdebug.so'

# Names of this library.
library_names='xdebug.so xdebug.so xdebug.so'

# The name of the static archive.
old_library=''

# Libraries that this one depends upon.
dependency_libs=' -lm'

# Version information for xdebug.
current=0
age=0
revision=0

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=yes

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/Users/cloudnik/www/Automattic/core/xdebug/modules'
Binary file added .libs/xdebug.o
Binary file not shown.
Binary file added .libs/xdebug.so
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/php-wasm/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

async function run() {
// @ts-ignore
const defaultPhpIniPath = await import('./php.ini');

Check failure on line 30 in packages/php-wasm/cli/src/main.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

'defaultPhpIniPath' is assigned a value but never used
const phpVersion = (process.env['PHP'] ||
LatestSupportedPHPVersion) as SupportedPHPVersion;
if (!SupportedPHPVersionsList.includes(phpVersion)) {
Expand Down Expand Up @@ -75,7 +75,7 @@

const hasMinusCOption = args.some((arg) => arg.startsWith('-c'));
if (!hasMinusCOption) {
args.unshift('-c', defaultPhpIniPath);
// args.unshift('-c', defaultPhpIniPath);
}

await php
Expand Down
22 changes: 14 additions & 8 deletions packages/php-wasm/compile/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ const argParser = yargs(process.argv.slice(2))
choices: ['yes', 'no'],
description: 'Build with mbregex support',
},
WITH_READLINE: {
type: 'string',
choices: ['yes', 'no'],
description: 'Build with Readline support',
},
WITH_CLI_SAPI: {
type: 'string',
choices: ['yes', 'no'],
Expand Down Expand Up @@ -126,16 +131,15 @@ const platformDefaults = {
WITH_OPENSSL: 'yes',
},
node: {
WITH_ICONV: 'yes',
WITH_LIBXML: 'yes',
WITH_LIBPNG: 'yes',
WITH_ICONV: 'yes',
WITH_MBSTRING: 'yes',
WITH_MBREGEX: 'yes',
// WITH_ICONV: 'yes',
// WITH_LIBXML: 'yes',
// WITH_LIBPNG: 'yes',
// WITH_MBSTRING: 'yes',
// WITH_MBREGEX: 'yes',
WITH_CLI_SAPI: 'yes',
WITH_OPENSSL: 'yes',
// WITH_OPENSSL: 'yes',
WITH_NODEFS: 'yes',
WITH_MYSQL: 'yes',
// WITH_MYSQL: 'yes',
WITH_WS_NETWORKING_PROXY: 'yes',
},
};
Expand Down Expand Up @@ -195,6 +199,8 @@ await asyncSpawn(
'--build-arg',
getArg('WITH_CLI_SAPI'),
'--build-arg',
getArg('WITH_READLINE'),
'--build-arg',
getArg('WITH_OPENSSL'),
'--build-arg',
getArg('WITH_NODEFS'),
Expand Down
33 changes: 26 additions & 7 deletions packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ARG WITH_SQLITE
ARG WITH_MYSQL
ARG WITH_OPENSSL
ARG WITH_ICONV
ARG WITH_READLINE
ARG WITH_SOURCEMAPS
ARG WITH_WS_NETWORKING_PROXY

Expand Down Expand Up @@ -93,22 +94,28 @@ RUN if [ "$WITH_LIBZIP" = "yes" ]; then \
fi;


# Add ncurses if needed and libedit if needed
RUN if [ "$WITH_CLI_SAPI" = "yes" ]; \
then \
# Configure build flags
echo -n ' --enable-phar --enable-cli=static --enable-readline --with-libedit=/root/lib ' >> /root/.php-configure-flags && \
echo -n ' --enable-phar --enable-cli=static ' >> /root/.php-configure-flags && \
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 ' \
>> /root/.emcc-php-wasm-sources && \
echo -n ', "_run_cli", "_wasm_add_cli_arg"' >> /root/.EXPORTED_FUNCTIONS && \
echo -n ' -DWITH_CLI_SAPI=1 -lncurses -ledit ' >> /root/.emcc-php-wasm-flags && \
# Disable dlopen() in the readline PHP extension
echo '#undef COMPILE_DL_READLINE' >> /root/php-src/main/php_config.h && \
/root/replace.sh 's/GET_SHELL_CB\(cb\);/(cb) = php_cli_get_shell_callbacks();/g' /root/php-src/ext/readline/readline_cli.c; \
echo -n ' -DWITH_CLI_SAPI=1 ' >> /root/.emcc-php-wasm-flags; \
else \
echo -n ' --disable-cli ' >> /root/.php-configure-flags; \
fi;

# Add ncurses if needed and libedit if needed
RUN if [ "$WITH_READLINE" = "yes" ]; \
then \
echo -n ' --enable-readline --with-libedit=/root/lib ' >> /root/.php-configure-flags && \
echo -n ' -lncurses -ledit ' >> /root/.emcc-php-wasm-flags && \
# Disable dlopen() in the readline PHP extension
/root/replace.sh 's/GET_SHELL_CB\(cb\);/(cb) = php_cli_get_shell_callbacks();/g' /root/php-src/ext/readline/readline_cli.c; \
echo '#undef COMPILE_DL_READLINE' >> /root/php-src/main/php_config.h; \
fi;

# Add Libxml2 if needed
RUN if [ "$WITH_LIBXML" = "yes" ]; \
then \
Expand Down Expand Up @@ -202,6 +209,9 @@ RUN if [ "$WITH_MYSQL" = "yes" ]; then \
echo -n ' --enable-mysql --enable-pdo --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd ' >> /root/.php-configure-flags; \
fi

# @TODO: Figure out why this is needed:
RUN sed -i 's/HARDCODED_INI/HARDCODED_INI2/g' /root/php-src/sapi/cli/php_cli.c

# Build the patched PHP
WORKDIR /root/php-src
RUN source /root/emsdk/emsdk_env.sh && \
Expand All @@ -225,7 +235,7 @@ RUN source /root/emsdk/emsdk_env.sh && \
--disable-all \
--enable-hash \
--enable-static=yes \
--enable-shared=no \
--enable-shared=yes \
--enable-session \
--enable-filter \
--enable-calendar \
Expand Down Expand Up @@ -434,6 +444,11 @@ RUN echo -n ' -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 ' >> /root/.emcc-php-w
"zif_fwrite",\
"php_stdiop_write",\
"zif_array_filter",\
"dlopen",\
"zend_load_extension",\
"zend_llist_apply",\
"php_ini_register_extensions",\
"php_load_zend_extension_cb",\
"zend_call_known_instance_method_with_2_params",\
"zend_fetch_dimension_address_read_R",\
"_zval_dtor_func_for_ptr",\
Expand Down Expand Up @@ -739,6 +754,7 @@ RUN set -euxo pipefail; \
mkdir -p /build/output; \
source /root/emsdk/emsdk_env.sh; \
export EXPORTED_FUNCTIONS=$'["_exit", \n\
"_compiler_globals", \n\
"_php_wasm_init", \n\
"_phpwasm_destroy_uploaded_files_hash", \n\
"_phpwasm_init_uploaded_files_hash", \n\
Expand Down Expand Up @@ -783,6 +799,7 @@ RUN set -euxo pipefail; \
-s INITIAL_MEMORY=1024MB \
-s ALLOW_MEMORY_GROWTH=1 \
-s ASSERTIONS=0 \
-s MAIN_MODULE \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s NODEJS_CATCH_EXIT=0 \
-s NODEJS_CATCH_REJECTION=0 \
Expand Down Expand Up @@ -876,6 +893,8 @@ RUN set -euxo pipefail; \
# wrapper function.
/root/replace.sh $'s/ENVIRONMENT_IS_([A-Z]+)\s*=\s*(true|false)/ENVIRONMENT_IS_$1=RuntimeName==="$1"/g' /root/output/php.js; \
/root/replace.sh 's/var ENV\s*=\s*\{/var ENV = PHPLoader.ENV || {/g' /root/output/php.js; \
/root/replace.sh 's/__dlopen_js\./__dlopen_js_unused./g' /root/output/php.js; \
/root/replace.sh 's/__dlopen_js\s*=/__dlopen_js_unused =/g' /root/output/php.js; \
# Turn the php.js file into an ES module
# Manually turn the output into a esm module instead of relying on -s MODULARIZE=1.
# which pollutes the global namespace and does not play well with import() mechanics.
Expand Down
6 changes: 6 additions & 0 deletions packages/php-wasm/compile/php/esm-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ export function init(RuntimeName, PHPLoader) {
}
}

const __dlopen_js = function (handle) {
var jsflags = { loadAsync: false }
return dlopenInternal(handle, jsflags);
};
__dlopen_js.isAsync = false;

// The rest of the code comes from the built php.js file and esm-suffix.js
6 changes: 6 additions & 0 deletions packages/php-wasm/compile/php/php_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1581,3 +1581,9 @@ int EMSCRIPTEN_KEEPALIVE del_callback(zend_function *fptr)
}
#endif

EMSCRIPTEN_KEEPALIVE void emscripten_console_log(char *a){}
EMSCRIPTEN_KEEPALIVE void emscripten_console_warn(char *a){}
EMSCRIPTEN_KEEPALIVE void emscripten_console_error(char *a){}
EMSCRIPTEN_KEEPALIVE void emscripten_out(char *a){}
EMSCRIPTEN_KEEPALIVE void emscripten_err(char *a){}
EMSCRIPTEN_KEEPALIVE void emscripten_dbg(char *a){}
Binary file modified packages/php-wasm/node/public/7_4_33/php_7_4.wasm
Binary file not shown.
Binary file modified packages/php-wasm/node/public/8_2_10/php_8_2.wasm
Binary file not shown.
Loading
Loading