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 fails when both -sJSPI and --emit-tsd are active #23272

Closed
mroohian opened this issue Dec 31, 2024 · 0 comments · Fixed by #23320
Closed

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

mroohian opened this issue Dec 31, 2024 · 0 comments · Fixed by #23320
Assignees

Comments

@mroohian
Copy link

mroohian commented Dec 31, 2024

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:
When enabling the JSPI flag and attempting to emit Typescript definitions (via --emit-tsd), the build fails. The error indicates that JSPI is not supported in the current environment. It seems that it tries to assert in Node context that WebAssembly.promising exists.

I suspect that the issue lies in tsgen.js, which appears to validate the generated codes but fails because Node.js does not support JSPI. However, the generated code works correctly in a browser environment when the JSPI flag is enabled.

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:

RuntimeError: Aborted(Assertion failed: JSPI not supported by current environment. Perhaps it needs to be enabled via flags?)
    at abort (C:\Users\User\AppData\Local\Temp\emscripten_temp_52rs7em6\tsgen.js:498:11)
    at assert (C:\Users\User\AppData\Local\Temp\emscripten_temp_52rs7em6\tsgen.js:231:5)
    at Object.instrumentWasmImports (C:\Users\User\AppData\Local\Temp\emscripten_temp_52rs7em6\tsgen.js:4548:9)
    at getWasmImports (C:\Users\User\AppData\Local\Temp\emscripten_temp_52rs7em6\tsgen.js:639:12)
    at createWasm (C:\Users\User\AppData\Local\Temp\emscripten_temp_52rs7em6\tsgen.js:689:14)
    at Object.<anonymous> (C:\Users\User\AppData\Local\Temp\emscripten_temp_52rs7em6\tsgen.js:4824:1)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)

Node.js v20.18.0
em++: error: 'C:/Users/User/Workspace/third-party/emsdk/node/20.18.0_64bit/bin/node.exe C:\Users\User\AppData\Local\Temp\emscripten_temp_52rs7em6\tsgen.js' failed (returned 1)
ninja: build stopped: subcommand failed.
brendandahl added a commit to brendandahl/emscripten that referenced this issue Jan 7, 2025
- Adds a Promise<T> wrapper around the return type for async embind functions.
- Disables JSPI while generating the definitions, since it's not needed.

Fixes emscripten-core#23272
brendandahl added a commit to brendandahl/emscripten that referenced this issue Jan 7, 2025
- Adds a Promise<T> wrapper around the return type for async embind functions.
- Disables JSPI while generating the definitions, since it's not needed.

Fixes emscripten-core#23272
brendandahl added a commit that referenced this issue Jan 8, 2025
- Adds a Promise<T> wrapper around the return type for async embind
functions.
- Disables JSPI while generating the definitions, since it's not needed.

Fixes #23272
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