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

Build still fails when both -sJSPI and --emit-tsd are active #23418

Open
mroohian opened this issue Jan 15, 2025 · 2 comments · May be fixed by #23419
Open

Build still fails when both -sJSPI and --emit-tsd are active #23418

mroohian opened this issue Jan 15, 2025 · 2 comments · May be fixed by #23419
Assignees

Comments

@mroohian
Copy link

mroohian commented Jan 15, 2025

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.74 (1092ec30a3fb1d46b1782ff1b4db5094d3d06ae5)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 322eb1a92e6d4266184060346616fa0dbe39e731)
Target: wasm32-unknown-emscripten
Thread model: posix

Issue:
This is a follow-up to #23272 because it was closed.

When enabling the JSPI flag and attempting to emit Typescript definitions (via --emit-tsd), the build fails. Since we disable Asyncify the library_async is not included and the linker complains about missing emscripten_sleep() function.

Demo to reproduce: https://github.com/mroohian/emscripten-jspi-demo

Failing command line in full:

# This command is executed by CMake
em++ -gsource-map \
     -lembind \
     --emit-tsd test1.d.ts \   # It works without this line
     -s EXPORT_NAME=Test1Module \
     -s JSPI \
     -s STRICT \
     -s USE_ES6_IMPORT_META \
     -s MODULARIZE \
     -s EXPORT_ES6=1 \
     --no-entry \
     test1.cpp.o \
     -o test1.js

Full link command and output with -v appended:

> [email protected] cmake:build
> cd build.em && make

-- Configuring done (1.2s)
-- Generating done (0.0s)
-- Build files have been written to: /root/workspace/emscripten-jspi-demo/build.em
[ 33%] Building CXX object CMakeFiles/test1.dir/src/wasm/calc.cpp.o
[ 66%] Building CXX object CMakeFiles/test1.dir/src/wasm/test1.cpp.o
[100%] Linking CXX executable test1.js
em++: warning: -sASYNCIFY=2 (JSPI) is still experimental [-Wexperimental]
error: undefined symbol: emscripten_sleep (referenced by root reference (e.g. compiled C/C++ code))
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _emscripten_sleep may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/root/workspace/emsdk/node/20.18.0_64bit/bin/node /root/workspace/emsdk/upstream/emscripten/src/compiler.mjs /tmp/tmpyi_gjmeb.json' failed (returned 1)
make[2]: *** [CMakeFiles/test1.dir/build.make:114: test1.js] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test1.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
@brendandahl
Copy link
Collaborator

We could either 1) require a compatible node version and keep JSPI enabled, 2) still link in library_async.js 3) make it so the JSPI feature detection only runs when an JSPI'd function is called. I don't really like any of those options, but 1 is probably the easiest. Unfortunately, we'll need a very current node to run with with the latest JSPI.

@mroohian
Copy link
Author

@brendandahl I'm fine with option 1 as long as we give a hint about the supported node version.

brendandahl added a commit to brendandahl/emscripten that referenced this issue Jan 15, 2025
Instead of disabling JSPI during TSD generation just skip instrumenting
the wasm exports and imports so JSPI isn't needed.

Fixes emscripten-core#23418
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

Successfully merging a pull request may close this issue.

2 participants