In my last post, I expressed frustration at how the lack of exnref
support in most WebAssembly runtimes made zeroperl effectively unusable. However, complaining alone doesn’t solve problems—if something is broken, fix it. Don’t accept the status quo or let it derail your goals.
Using libsetjmp
from the WASI SDK for setjmp/longjmp
breaks compatibility across WebAssembly runtimes, so I decided to implement it myself. Binaryen has an Asyncify feature, which provides more than enough functionality to build a setjmp
implementation from scratch.1
First, we remove the official library
Next, we write some (web)assembly
Then, we run wasm-opt
wasm-opt zeroperl_unopt -O3 \
--strip-dwarf \
--enable-bulk-memory \
--asyncify \
-o zeroperl.wasm
And the moment of truth…
zeroperl now runs in Wasmer, Wasmtime, and every other WebAssembly runtime I tested.
Enjoy your fully sandboxed and self-contained Perl. All in one tiny WebAssembly module. Source code here.
Okay, not from scratch, I found a solution in the Ruby repo of all places (which itself just mirrors how Emscripten implements setjmp)