Skip to content

Commit 5a84c36

Browse files
authored
embind: Fix tsgen when Wasm exceptions and assertions are enabled. (#20999)
When exceptions and assertions are enabled the Wasm binary needs several symbols that will not be defined if we disable WASM_EXCEPTIONS during TS generation. Instead of disabling, just enable exception handling when running node. Fixes: #20949
1 parent 9916033 commit 5a84c36

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

test/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,12 @@ def test_embind_tsgen_memory64(self):
31093109
self.get_emcc_args())
31103110
self.assertFileContents(test_file('other/embind_tsgen_memory64.d.ts'), read_file('embind_tsgen_memory64.d.ts'))
31113111

3112+
def test_embind_tsgen_exceptions(self):
3113+
# Check that when Wasm exceptions and assertions are enabled bindings still generate.
3114+
self.run_process([EMCC, test_file('other/embind_tsgen.cpp'),
3115+
'-lembind', '--embind-emit-tsd', 'embind_tsgen.d.ts', '-fwasm-exceptions', '-sASSERTIONS'])
3116+
self.assertFileContents(test_file('other/embind_tsgen.d.ts'), read_file('embind_tsgen.d.ts'))
3117+
31123118
def test_emconfig(self):
31133119
output = self.run_process([emconfig, 'LLVM_ROOT'], stdout=PIPE).stdout.strip()
31143120
self.assertEqual(output, config.LLVM_ROOT)

tools/link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,6 @@ def run_embind_gen(wasm_target, js_syms, extra_settings):
19361936
setup_environment_settings()
19371937
# Use a separate Wasm file so the JS does not need to be modified after emscripten.emscript.
19381938
settings.SINGLE_FILE = False
1939-
# Disable support for wasm exceptions
1940-
settings.WASM_EXCEPTIONS = False
19411939
# Embind may be included multiple times, de-duplicate the list first.
19421940
settings.JS_LIBRARIES = dedup_list(settings.JS_LIBRARIES)
19431941
# Replace embind with the TypeScript generation version.
@@ -1951,6 +1949,8 @@ def run_embind_gen(wasm_target, js_syms, extra_settings):
19511949
node_args = []
19521950
if settings.MEMORY64:
19531951
node_args += shared.node_memory64_flags()
1952+
if settings.WASM_EXCEPTIONS:
1953+
node_args += shared.node_exception_flags()
19541954
# Run the generated JS file with the proper flags to generate the TypeScript bindings.
19551955
out = shared.run_js_tool(outfile_js, [], node_args, stdout=PIPE)
19561956
settings.restore(original_settings)

tools/shared.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ def node_memory64_flags():
397397
return ['--experimental-wasm-memory64']
398398

399399

400+
def node_exception_flags():
401+
return ['--experimental-wasm-eh']
402+
403+
400404
def node_pthread_flags(nodejs):
401405
node_version = get_node_version(nodejs)
402406
# bulk memory and wasm threads were enabled by default in node v16.

0 commit comments

Comments
 (0)