@@ -5,14 +5,35 @@ MRuby::Toolchain.new(:emscripten) do |conf|
|
5 | 5 | # - https://emscripten.org/docs/tools_reference/emcc.html |
6 | 6 | # - https://emscripten.org/docs/tools_reference/settings_reference.html |
7 | 7 | # - https://github.com/emscripten-core/emscripten/blob/main/src/settings.js |
| 8 | +# |
| 9 | +# == WASM Exception Handling == |
| 10 | +# |
| 11 | +# mruby uses setjmp/longjmp for non-local exits (exceptions, break/return |
| 12 | +# from blocks). This toolchain uses native WASM exception handling which |
| 13 | +# is more efficient than Asyncify-based emulation: |
| 14 | +# |
| 15 | +# - Minimal memory overhead (no shadow stack) |
| 16 | +# - No code size penalty |
| 17 | +# - Works with both C and C++ code |
| 18 | +# |
| 19 | +# Supported runtimes (as of 2024): |
| 20 | +# - Chrome 95+, Firefox 100+, Safari 15.2+ |
| 21 | +# - Node.js 17+, Wasmtime, Wasmer |
| 22 | +# |
| 23 | +# For older runtimes, override with CFLAGS/LDFLAGS environment variables. |
| 24 | +# |
| 25 | +# See: https://emscripten.org/docs/porting/exceptions.html |
| 26 | +# https://emscripten.org/docs/porting/setjmp-longjmp.html |
8 | 27 | compile_and_link_flags = [ |
| 28 | +'-fwasm-exceptions', |
9 | 29 | ] |
10 | 30 | compile_flags = [ |
11 | 31 | *compile_and_link_flags, |
12 | 32 | '-Wno-unused-but-set-variable', |
13 | 33 | ] |
14 | 34 | link_flags = [ |
15 | 35 | *compile_and_link_flags, |
| 36 | +'-sSUPPORT_LONGJMP=wasm', |
16 | 37 | ] |
17 | 38 | |
18 | 39 | conf.cc do |cc| |
|