Skip to content

Commit aabf055

Browse files
committed
Correct errors from upgrading emscripten
1 parent 8cb6e9b commit aabf055

File tree

5 files changed

+16
-38
lines changed

5 files changed

+16
-38
lines changed

packages/php-wasm/compile/php/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,13 +2226,7 @@ RUN set -euxo pipefail; \
22262226
source /root/emsdk/emsdk_env.sh; \
22272227
if [ "$WITH_JSPI" = "yes" ]; then \
22282228
# Both imports and exports are required for inter-module communication with wrapped methods, e.g., wasm_recv.
2229-
export JSPI_ADD_IMPORTS=""; \
2230-
export JSPI_ADD_EXPORTS=""; \
2231-
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
2232-
export JSPI_ADD_IMPORTS=",fd_close"; \
2233-
export JSPI_ADD_EXPORTS=",fd_close"; \
2234-
fi; \
2235-
export ASYNCIFY_FLAGS=" -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_IMPORTS=js_open_process,js_fd_read,js_waitpid,js_process_status,js_create_input_device,wasm_setsockopt,wasm_shutdown,wasm_close,wasm_recv,__syscall_fcntl64,js_flock,js_release_file_locks,js_waitpid$JSPI_ADD_IMPORTS -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,wasm_recv,__wasm_call_ctors$JSPI_ADD_EXPORTS -s EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports "; \
2229+
export ASYNCIFY_FLAGS=" -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_IMPORTS=js_open_process,js_fd_read,js_waitpid,js_process_status,js_create_input_device,wasm_setsockopt,wasm_shutdown,wasm_close,wasm_recv,__syscall_fcntl64,js_flock,js_release_file_locks,js_waitpid -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,wasm_recv,__wasm_call_ctors,__errno_location -s EXPORTED_RUNTIME_METHODS=HEAPU32,HEAPU8,ccall,PROXYFS,wasmExports "; \
22362230
echo '#define PLAYGROUND_JSPI 1' > /root/php_wasm_asyncify.h; \
22372231
else \
22382232
export ASYNCIFY_FLAGS=" -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 -s EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports $(cat /root/.emcc-php-asyncify-flags) "; \
@@ -2243,6 +2237,7 @@ RUN set -euxo pipefail; \
22432237
"stringToUTF8", \n\
22442238
"lengthBytesUTF8", \n\
22452239
"FS", \n\
2240+
"___errno_location", \n\
22462241
"___wrap_select", \n\
22472242
"_wasm_set_sapi_name", \n\
22482243
"_php_wasm_init", \n\
@@ -2403,6 +2398,11 @@ RUN set -euxo pipefail; \
24032398
# wrapper function.
24042399
/root/replace.sh $'s/ENVIRONMENT_IS_([A-Z]+)\s*=\s*(true|false)/ENVIRONMENT_IS_$1=RuntimeName==="$1"/g' /root/output/php.js; \
24052400
/root/replace.sh 's/var ENV\s*=\s*\{/var ENV = PHPLoader.ENV || {/g' /root/output/php.js; \
2401+
# Expose required functions to the module.
2402+
# Emscripten 4.0.10 removed the runtime exposure of `_malloc` and `_free`,
2403+
# so we rebind them from `wasmExports` and attach them to PHPLoader.
2404+
/root/replace.sh "s/_free\s*=\s*wasmExports\['free'\];/_free = PHPLoader['free'] = wasmExports['free'];/g" /root/output/php.js; \
2405+
/root/replace.sh "s/_malloc\s*=\s*wasmExports\['malloc'\];/_malloc = PHPLoader['malloc'] = wasmExports['malloc'];/g" /root/output/php.js; \
24062406
# Patch Emscripten exit status to include a stack trace
24072407
# Override Emscripten's default ExitStatus class which gets
24082408
# thrown on failure. Unfortunately, the default object is not

packages/php-wasm/compile/php/esm-suffix.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,6 @@ PHPLoader['removeRunDependency'] = function (...args) {
3636
}
3737
}
3838

39-
/**
40-
* Other exports live in the Dockerfile in:
41-
*
42-
* * EXPORTED_RUNTIME_METHODS
43-
* * EXPORTED_FUNCTIONS
44-
*
45-
* These exports, however, live in here because:
46-
*
47-
* * Listing them in EXPORTED_RUNTIME_METHODS doesn't actually
48-
* export them. This could be a bug in Emscripten or a consequence of
49-
* that option being deprecated.
50-
* * Listing them in EXPORTED_FUNCTIONS works, but they are overridden
51-
* on every `BasePHP.run()` call. This is a problem because we want to
52-
* spy on these calls in some unit tests.
53-
*
54-
* Therefore, we export them here.
55-
*/
56-
PHPLoader['malloc'] = _malloc;
57-
PHPLoader['free'] = typeof _free === 'function' ? _free : PHPLoader['_wasm_free'];
58-
5939
if (typeof NODEFS === 'object') {
6040
// We override NODEFS.createNode() to add an `isSharedFS` flag to all NODEFS
6141
// nodes. This way we can tell whether file-locking is needed and possible

packages/php-wasm/compile/php/phpwasm-emscripten-library.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,13 @@ const LibraryExample = {
434434
envLength
435435
) {
436436
if (!command) {
437-
setErrNo(ERRNO_CODES.EINVAL);
437+
___errno_location(ERRNO_CODES.EINVAL);
438438
return -1;
439439
}
440440

441441
const cmdstr = UTF8ToString(command);
442442
if (!cmdstr.length) {
443-
setErrNo(ERRNO_CODES.EINVAL);
443+
___errno_location(ERRNO_CODES.EINVAL);
444444
return -1;
445445
}
446446

@@ -504,11 +504,11 @@ const LibraryExample = {
504504
}
505505
} catch (e) {
506506
if (e.code === 'SPAWN_UNSUPPORTED') {
507-
setErrNo(ERRNO_CODES.ENOSYS);
507+
___errno_location(ERRNO_CODES.ENOSYS);
508508
return -1;
509509
}
510510
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
511-
setErrNo(e.code);
511+
___errno_location(e.code);
512512
return -1;
513513
}
514514

@@ -659,7 +659,7 @@ const LibraryExample = {
659659
try {
660660
stdinStream = SYSCALLS.getStreamFromFD(stdinChildFd);
661661
} catch (e) {
662-
setErrNo(ERRNO_CODES.EBADF);
662+
___errno_location(ERRNO_CODES.EBADF);
663663
return ProcInfo.pid;
664664
}
665665
if (!stdinStream?.node) {
@@ -722,7 +722,7 @@ const LibraryExample = {
722722
) {
723723
throw e;
724724
}
725-
setErrNo(e.errno);
725+
___errno_location(e.errno);
726726
stopPumpingAndCloseStdin();
727727
}
728728
};
@@ -731,9 +731,9 @@ const LibraryExample = {
731731
if (!cp.stdin.closed) {
732732
cp.stdin.end();
733733
}
734-
PHPLoader["free"](buffer);
735-
PHPLoader["free"](iov);
736-
PHPLoader["free"](pnum);
734+
_free(buffer);
735+
_free(iov);
736+
_free(pnum);
737737
}
738738

739739
// pump() can never alter the result of this function.

packages/php-wasm/compile/shared/intl/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ RUN cd /root && git apply --no-index /root/php${PHP_VERSION:0:3}*.patch -v
5959
RUN source /root/emsdk/emsdk_env.sh && \
6060
cd php-src && \
6161
emconfigure ./configure \
62-
--host=i386-unknown-freebsd \
6362
--disable-fiber-asm \
6463
--enable-embed \
6564
--disable-cgi \

packages/php-wasm/compile/xdebug/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ RUN cd /root && git apply --no-index /root/php${PHP_VERSION:0:3}*.patch -v
5353
RUN source /root/emsdk/emsdk_env.sh && \
5454
cd php-src && \
5555
emconfigure ./configure \
56-
--host=i386-unknown-freebsd \
5756
--disable-fiber-asm \
5857
--enable-embed \
5958
--disable-cgi \

0 commit comments

Comments
 (0)