Skip to content

Failed to build Docker containers due to Emscripten error #152

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

Closed
nsfisis opened this issue Mar 10, 2024 · 4 comments
Closed

Failed to build Docker containers due to Emscripten error #152

nsfisis opened this issue Mar 10, 2024 · 4 comments

Comments

@nsfisis
Copy link

nsfisis commented Mar 10, 2024

Summary

I tried to build the Docker containers by make build, but it failed with the below error message:

25.42 file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:382
25.42         if (param.type === 'RestElement') {
25.42                   ^
25.42
25.42 TypeError: Cannot read properties of null (reading 'type')
25.42     at traverse (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:382:19)
25.42     at traverse (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:391:13)
25.42     at Array.forEach (<anonymous>)
25.42     at handleFunction (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:381:19)
25.42     at Object.ArrowFunctionExpression (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:470:9)
25.42     at c (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:92:20)
25.42     at recursiveWalk (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:94:5)
25.42     at file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:90:38
25.42     at maybeChild (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:54:7)
25.42     at Array.forEach (<anonymous>)

It ocurred for all versions, i.e., from build-5.6 to build-8.3.

Environment

  • OS: WSL on Windows 11
  • WSL OS: Ubuntu 22.04.3 LTS
  • Build date: 2024-03-10 09:18 (Asia/Tokyo)

More detailed log

 > [emscripten-php 46/48] RUN source /root/emsdk/emsdk_env.sh &&     export EXPORTED_FUNCTIONS=$'["_php_wasm_init", \n"_phpwasm_destroy_uploaded_files_hash", \n"_phpwasm_init_uploaded_files_hash", \n"_phpwasm_register_uploaded_file", \n"_wasm_set_phpini_path", \n"_wasm_set_phpini_entries", \n"_wasm_add_SERVER_entry", \n"_wasm_add_uploaded_file", \n"_wasm_sapi_handle_request", \n"_wasm_set_content_length", \n"_wasm_set_content_type", \n"_wasm_set_cookies", \n"_wasm_set_path_translated", \n"_wasm_set_php_code", \n"_wasm_set_query_string", \n"_wasm_set_request_body", \n"_wasm_set_request_host", \n"_wasm_set_request_method", \n"_wasm_set_request_port", \n"_wasm_set_request_uri", \n"_wasm_set_skip_shebang" '"$(cat /root/.EXPORTED_FUNCTIONS)"']';     emcc -O3     --js-library /root/phpwasm-emscripten-library.js     -I .      -I ext       -I ext/json       -I Zend      -I main      -I TSRM/     -I /root/lib/include     -L/root/lib -L/root/lib/lib/     $(cat /root/.emcc-php-wasm-flags)     -o /root/output/php.js     -s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS"     -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS", "PROXYFS"]'     -s INITIAL_MEMORY=1024MB     -s ALLOW_MEMORY_GROWTH=1             -s ASSERTIONS=0                      -s ERROR_ON_UNDEFINED_SYMBOLS=0      -s INVOKE_RUN=0                      -s EXIT_RUNTIME=1                        /root/lib/libphp.a         /root/php_wasm.c         $(cat /root/.emcc-php-wasm-sources)     -s ENVIRONMENT=web     -s FORCE_FILESYSTEM=1     -s EXPORT_NAME="'PHPLoader'":
0.414 Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)
0.414 Adding directories to PATH:
0.414 PATH += /root/emsdk
0.414 PATH += /root/emsdk/upstream/emscripten
0.414 PATH += /root/emsdk/node/16.20.0_64bit/bin
0.414
0.414 Setting environment variables:
0.414 PATH = /root/emsdk:/root/emsdk/upstream/emscripten:/root/emsdk/node/16.20.0_64bit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
0.414 EMSDK = /root/emsdk
0.414 EMSDK_NODE = /root/emsdk/node/16.20.0_64bit/bin/node
0.763 emcc2: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
0.779 cache:INFO: generating system asset: symbol_lists/d85b8c507ae858326ef72680e2ed9bfab3e98ece.json... (this will be cached in "/root/emsdk/upstream/emscripten/cache/symbol_lists/d85b8c507ae858326ef72680e2ed9bfab3e98ece.json" for subsequent builds)
0.972 cache:INFO:  - ok
1.813 warning: undefined symbol: getcontext (referenced by root reference (e.g. compiled C/C++ code))
1.813 warning: undefined symbol: getdtablesize (referenced by root reference (e.g. compiled C/C++ code))
1.813 warning: undefined symbol: makecontext (referenced by root reference (e.g. compiled C/C++ code))
1.814 warning: undefined symbol: swapcontext (referenced by root reference (e.g. compiled C/C++ code))
1.814 warning: undefined symbol: vrzno_del_callback (referenced by root reference (e.g. compiled C/C++ code))
1.814 warning: undefined symbol: vrzno_exec_callback (referenced by root reference (e.g. compiled C/C++ code))
1.833 warning: invalid item in EXPORTED_RUNTIME_METHODS: PROXYFS
1.854 emcc2: warning: warnings in JS library compilation [-Wjs-compiler]
25.42 file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:382
25.42         if (param.type === 'RestElement') {
25.42                   ^
25.42
25.42 TypeError: Cannot read properties of null (reading 'type')
25.42     at traverse (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:382:19)
25.42     at traverse (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:391:13)
25.42     at Array.forEach (<anonymous>)
25.42     at handleFunction (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:381:19)
25.42     at Object.ArrowFunctionExpression (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:470:9)
25.42     at c (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:92:20)
25.42     at recursiveWalk (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:94:5)
25.42     at file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:90:38
25.42     at maybeChild (file:///root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs:54:7)
25.42     at Array.forEach (<anonymous>)
25.42 emcc2: error: '/root/emsdk/node/16.20.0_64bit/bin/node /root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs /tmp/emscripten_temp_dc143ue4/php.js AJSDCE minifyWhitespace -o /tmp/emscripten_temp_dc143ue4/php.jso1.js' failed (returned 1)
------
Dockerfile:843
--------------------
 842 |     COPY build-assets/phpwasm-emscripten-library.js /root/phpwasm-emscripten-library.js
 843 | >>> RUN source /root/emsdk/emsdk_env.sh && \
 844 | >>>     export EXPORTED_FUNCTIONS=$'["_php_wasm_init", \n\
 845 | >>> "_phpwasm_destroy_uploaded_files_hash", \n\
 846 | >>> "_phpwasm_init_uploaded_files_hash", \n\
 847 | >>> "_phpwasm_register_uploaded_file", \n\
 848 | >>> "_wasm_set_phpini_path", \n\
 849 | >>> "_wasm_set_phpini_entries", \n\
 850 | >>> "_wasm_add_SERVER_entry", \n\
 851 | >>> "_wasm_add_uploaded_file", \n\
 852 | >>> "_wasm_sapi_handle_request", \n\
 853 | >>> "_wasm_set_content_length", \n\
 854 | >>> "_wasm_set_content_type", \n\
 855 | >>> "_wasm_set_cookies", \n\
 856 | >>> "_wasm_set_path_translated", \n\
 857 | >>> "_wasm_set_php_code", \n\
 858 | >>> "_wasm_set_query_string", \n\
 859 | >>> "_wasm_set_request_body", \n\
 860 | >>> "_wasm_set_request_host", \n\
 861 | >>> "_wasm_set_request_method", \n\
 862 | >>> "_wasm_set_request_port", \n\
 863 | >>> "_wasm_set_request_uri", \n\
 864 | >>> "_wasm_set_skip_shebang" '"$(cat /root/.EXPORTED_FUNCTIONS)"']'; \
 865 | >>>     emcc -O3 \
 866 | >>>     --js-library /root/phpwasm-emscripten-library.js \
 867 | >>>     -I .  \
 868 | >>>     -I ext   \
 869 | >>>     -I ext/json   \
 870 | >>>     -I Zend  \
 871 | >>>     -I main  \
 872 | >>>     -I TSRM/ \
 873 | >>>     -I /root/lib/include \
 874 | >>>     -L/root/lib -L/root/lib/lib/ \
 875 | >>>     $(cat /root/.emcc-php-wasm-flags) \
 876 | >>>     -o /root/output/php.js \
 877 | >>>     -s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" \
 878 | >>>     -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS", "PROXYFS"]' \
 879 | >>>     -s INITIAL_MEMORY=1024MB \
 880 | >>>     -s ALLOW_MEMORY_GROWTH=1         \
 881 | >>>     -s ASSERTIONS=0                  \
 882 | >>>     -s ERROR_ON_UNDEFINED_SYMBOLS=0  \
 883 | >>>     -s INVOKE_RUN=0                  \
 884 | >>>     -s EXIT_RUNTIME=1                \
 885 | >>>         /root/lib/libphp.a \
 886 | >>>         /root/php_wasm.c \
 887 | >>>         $(cat /root/.emcc-php-wasm-sources) \
 888 | >>>     -s ENVIRONMENT=$EMSCRIPTEN_ENVIRONMENT \
 889 | >>>     -s FORCE_FILESYSTEM=1 \
 890 | >>>     -s EXPORT_NAME="'PHPLoader'"
 891 |         # Emscripten complains it can't find some Asyncify functions
--------------------
ERROR: failed to solve: process "/bin/bash -c source /root/emsdk/emsdk_env.sh &&     export EXPORTED_FUNCTIONS=$'[\"_php_wasm_init\", \\n\"_phpwasm_destroy_uploaded_files_hash\", \\n\"_phpwasm_init_uploaded_files_hash\", \\n\"_phpwasm_register_uploaded_file\", \\n\"_wasm_set_phpini_path\", \\n\"_wasm_set_phpini_entries\", \\n\"_wasm_add_SERVER_entry\", \\n\"_wasm_add_uploaded_file\", \\n\"_wasm_sapi_handle_request\", \\n\"_wasm_set_content_length\", \\n\"_wasm_set_content_type\", \\n\"_wasm_set_cookies\", \\n\"_wasm_set_path_translated\", \\n\"_wasm_set_php_code\", \\n\"_wasm_set_query_string\", \\n\"_wasm_set_request_body\", \\n\"_wasm_set_request_host\", \\n\"_wasm_set_request_method\", \\n\"_wasm_set_request_port\", \\n\"_wasm_set_request_uri\", \\n\"_wasm_set_skip_shebang\" '\"$(cat /root/.EXPORTED_FUNCTIONS)\"']';     emcc -O3     --js-library /root/phpwasm-emscripten-library.js     -I .      -I ext       -I ext/json       -I Zend      -I main      -I TSRM/     -I /root/lib/include     -L/root/lib -L/root/lib/lib/     $(cat /root/.emcc-php-wasm-flags)     -o /root/output/php.js     -s EXPORTED_FUNCTIONS=\"$EXPORTED_FUNCTIONS\"     -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"UTF8ToString\", \"lengthBytesUTF8\", \"FS\", \"PROXYFS\"]'     -s INITIAL_MEMORY=1024MB     -s ALLOW_MEMORY_GROWTH=1             -s ASSERTIONS=0                      -s ERROR_ON_UNDEFINED_SYMBOLS=0      -s INVOKE_RUN=0                      -s EXIT_RUNTIME=1                        /root/lib/libphp.a         /root/php_wasm.c         $(cat /root/.emcc-php-wasm-sources)     -s ENVIRONMENT=$EMSCRIPTEN_ENVIRONMENT     -s FORCE_FILESYSTEM=1     -s EXPORT_NAME=\"'PHPLoader'\"" did not complete successfully: exit code: 1
make: *** [Makefile:24: build-image] Error 1
@nsfisis
Copy link
Author

nsfisis commented Mar 10, 2024

Active version of Emsdk in my environment:

$ docker run --rm tmp-php-wasm:5.6 sh /root/emsdk/emsdk list

The *recommended* precompiled SDK download is 3.1.54 (aa1588cd28c250a60457b5ed342557c762f416e3).

To install/activate it use:
         latest

This is equivalent to installing/activating:
         3.1.54             INSTALLED

All recent (non-legacy) installable versions are:
         3.1.54    INSTALLED
         3.1.54-asserts
         3.1.53
         3.1.53-asserts
         3.1.52
         3.1.52-asserts
         3.1.51
         3.1.51-asserts
         3.1.50
         3.1.50-asserts
         3.1.49
         3.1.49-asserts
         3.1.48
         3.1.48-asserts
         3.1.47
         3.1.47-asserts
         3.1.46
         3.1.46-asserts
         3.1.45
         3.1.45-asserts
         3.1.44
         3.1.44-asserts
         3.1.43
         3.1.43-asserts
         3.1.42
         3.1.42-asserts
         3.1.41
         3.1.41-asserts
         3.1.40
         3.1.40-asserts
         3.1.39
         3.1.39-asserts
         3.1.38
         3.1.38-asserts
         3.1.37
         3.1.37-asserts
         3.1.36
         3.1.36-asserts
         3.1.35
         3.1.35-asserts
         3.1.34
         3.1.34-asserts
         3.1.33
         3.1.33-asserts
         3.1.32
         3.1.32-asserts
         3.1.31
         3.1.31-asserts
         3.1.30
         3.1.30-asserts
         3.1.29
         3.1.29-asserts
         3.1.28
         3.1.28-asserts
         3.1.27
         3.1.27-asserts
         3.1.26
         3.1.26-asserts
         3.1.25
         3.1.25-asserts
         3.1.24
         3.1.24-asserts
         3.1.23
         3.1.23-asserts
         3.1.22
         3.1.22-asserts
         3.1.21
         3.1.21-asserts
         3.1.20
         3.1.20-asserts
         3.1.19
         3.1.19-asserts
         3.1.18
         3.1.18-asserts
         3.1.17
         3.1.17-asserts
         3.1.16
         3.1.16-asserts
         3.1.15
         3.1.15-asserts
         3.1.14
         3.1.14-asserts
         3.1.13
         3.1.13-asserts
         3.1.12
         3.1.12-asserts
         3.1.11
         3.1.11-asserts
         3.1.10
         3.1.10-asserts
         3.1.9
         3.1.9-asserts
         3.1.8
         3.1.8-asserts
         3.1.7
         3.1.7-asserts
         3.1.6
         3.1.6-asserts
         3.1.5
         3.1.5-asserts
         3.1.4
         3.1.4-asserts
         3.1.3
         3.1.3-asserts
         3.1.2
         3.1.2-asserts
         3.1.1
         3.1.1-asserts
         3.1.0
         3.1.0-asserts
         3.0.1
         3.0.1-asserts
         3.0.0
         3.0.0-asserts
         2.0.34
         2.0.33
         2.0.32
         2.0.31
         2.0.31-asserts
         2.0.30
         2.0.30-asserts
         2.0.29
         2.0.29-lto
         2.0.28
         2.0.28-lto
         2.0.27
         2.0.27-lto
         2.0.26
         2.0.26-lto
         2.0.25
         2.0.24
         2.0.23
         2.0.23-lto
         2.0.22
         2.0.21
         2.0.20
         2.0.20-lto
         2.0.19
         2.0.19-lto
         2.0.18
         2.0.17
         2.0.16
         2.0.15
         2.0.14
         2.0.13
         2.0.12
         2.0.11
         2.0.10
         2.0.9
         2.0.8
         2.0.7
         2.0.6
         2.0.5
         2.0.4
         2.0.3
         2.0.2
         2.0.1
         2.0.0
         1.40.1
         1.40.0
         1.39.20
         1.39.19
         1.39.18
         1.39.17
         1.39.16
         1.39.15
         1.39.14
         1.39.13
         1.39.12
         1.39.11
         1.39.10
         1.39.9
         1.39.8
         1.39.7
         1.39.6
         1.39.5
         1.39.4
         1.39.3
         1.39.2
         1.39.1
         1.39.0
         1.38.48
         1.38.47
         1.38.46
         1.38.45
         1.38.44
         1.38.43
         1.38.42
         1.38.41
         1.38.40
         1.38.39
         1.38.38
         1.38.37
         1.38.36
         1.38.35
         1.38.34
         1.38.33

The additional following precompiled SDKs are also available for download:
    *    sdk-releases-aa1588cd28c250a60457b5ed342557c762f416e3-64bit    INSTALLED
         sdk-releases-d525f56cb765ed6884a0c443dbb906b63b148915-64bit

The following SDKs can be compiled from source:
         sdk-main-64bit
         sdk-main-32bit

The following precompiled tool packages are available for download:
    (*)    releases-aa1588cd28c250a60457b5ed342557c762f416e3-64bit      INSTALLED
           releases-d525f56cb765ed6884a0c443dbb906b63b148915-64bit
           node-14.18.2-64bit
           node-14.15.5-64bit
           node-15.14.0-64bit
    (*)    node-16.20.0-64bit           INSTALLED
           emscripten-tag-1.38.30-32bit
           emscripten-tag-1.38.31-32bit
           emscripten-tag-1.38.30-64bit
           emscripten-tag-1.38.31-64bit
           emscripten-1.38.30
           emscripten-1.38.31

The following tools can be compiled from source:
           llvm-git-main-32bit
           llvm-git-main-64bit
           binaryen-tag-1.38.30-32bit
           binaryen-tag-1.38.31-32bit
           binaryen-tag-1.38.30-64bit
           binaryen-tag-1.38.31-64bit
           emscripten-main-32bit
           emscripten-main-64bit
           binaryen-main-32bit
           binaryen-main-64bit
           ninja-git-release-64bit
           ccache-git-emscripten-64bit

Items marked with * are activated for the current user.
Items marked with (*) are selected for use, but your current shell environment is not configured to use them. Type "source ./emsdk_env.sh" to set up your current shell to use them.

To access the historical archived versions, type 'emsdk list --old'

Run "git pull" to pull in the latest list.

@nsfisis
Copy link
Author

nsfisis commented Mar 10, 2024

I found out that this is caused by Emscripten's regression bug. I will report it to Emscripten.

@nsfisis nsfisis closed this as completed Mar 10, 2024
@nsfisis
Copy link
Author

nsfisis commented Mar 10, 2024

@nsfisis
Copy link
Author

nsfisis commented Mar 10, 2024

[Workaround] apply this patch:

diff --git a/src/wasm/Dockerfile b/src/wasm/Dockerfile
index dab2fd5..003e372 100644
--- a/src/wasm/Dockerfile
+++ b/src/wasm/Dockerfile
@@ -840,6 +840,7 @@ fi;
 # Build the final .wasm file
 RUN mkdir /root/output
 COPY build-assets/phpwasm-emscripten-library.js /root/phpwasm-emscripten-library.js
+RUN sed -i -e 's/for (var elem of param.elements) {/for (var elem of param.elements) { if (elem)/' /root/emsdk/upstream/emscripten/tools/acorn-optimizer.mjs
 RUN source /root/emsdk/emsdk_env.sh && \
     export EXPORTED_FUNCTIONS=$'["_php_wasm_init", \n\
 "_phpwasm_destroy_uploaded_files_hash", \n\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant