Skip to content

Commit cd295c0

Browse files
leftibotclaude
andcommitted
Address review: switch WASM EH to -fexceptions, restore Asyncify
Native wasm exceptions (-fwasm-exceptions) are incompatible with legacy Asyncify, and JSPI is not yet available in all browsers. Switch the Emscripten exception model to -fexceptions (JS-based) and restore -sASYNCIFY=1 / -sASYNCIFY_STACK_SIZE so the WASM build keeps working across every browser that supports threads, until JSPI is universally available. Requested by @lefticus in PR #156 review. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2521055 commit cd295c0

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

cmake/Emscripten.cmake

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ if(EMSCRIPTEN)
4242
"Initial WASM memory in bytes (default: 32MB)")
4343
set(myproject_WASM_PTHREAD_POOL_SIZE "4" CACHE STRING
4444
"Pthread pool size for WASM builds (default: 4)")
45-
46-
# For Emscripten WASM builds, FTXUI requires pthreads and native exception handling
47-
# Set these flags early so they propagate to all dependencies
48-
add_compile_options(-pthread -fwasm-exceptions)
49-
add_link_options(-pthread -fwasm-exceptions)
45+
set(myproject_WASM_ASYNCIFY_STACK_SIZE "65536" CACHE STRING
46+
"Asyncify stack size in bytes (default: 64KB)")
47+
48+
# For Emscripten WASM builds, FTXUI requires pthreads and exception handling.
49+
# We use -fexceptions (JS-based exceptions) rather than -fwasm-exceptions
50+
# because native wasm exceptions are incompatible with legacy Asyncify, and
51+
# JSPI (the modern Asyncify replacement) is not yet shipping in all browsers.
52+
# Set these flags early so they propagate to all dependencies.
53+
add_compile_options(-pthread -fexceptions)
54+
add_link_options(-pthread -fexceptions)
5055
endif()
5156

5257
# Function to apply WASM settings to a target
@@ -87,11 +92,11 @@ function(myproject_configure_wasm_target target)
8792
"-sUSE_PTHREADS=1"
8893
"-sPROXY_TO_PTHREAD=1"
8994
"-sPTHREAD_POOL_SIZE=${myproject_WASM_PTHREAD_POOL_SIZE}"
90-
# Enable JSPI (JavaScript Promise Integration) for emscripten_sleep
91-
# and other async operations. JSPI is the modern replacement for
92-
# legacy Asyncify (-sASYNCIFY=1) and, unlike Asyncify, is compatible
93-
# with native WebAssembly exception handling (-fwasm-exceptions).
94-
"-sJSPI=1"
95+
# Enable Asyncify for emscripten_sleep and other async operations.
96+
# Paired with -fexceptions (JS-based exception handling) above, since
97+
# Asyncify is not compatible with native wasm exceptions.
98+
"-sASYNCIFY=1"
99+
"-sASYNCIFY_STACK_SIZE=${myproject_WASM_ASYNCIFY_STACK_SIZE}"
95100
# Memory configuration
96101
"-sALLOW_MEMORY_GROWTH=1"
97102
"-sINITIAL_MEMORY=${myproject_WASM_INITIAL_MEMORY}"

0 commit comments

Comments
 (0)