Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -926,13 +926,20 @@ namespace :wasm do

desc "Build the RBS parser as a WebAssembly module (requires WASI_SDK_PATH)"
task :build do
# `-DNDEBUG` compiles out `RBS_ASSERT`, the same way ext/rbs_extension does
# for the MRI extension. The assertions sit in the lexer and the constant
# pool, so keeping them costs about 20% of parse time; set `DEBUG=1` to keep
# them when debugging the module itself.
debug_flags = ENV["DEBUG"] ? [] : ["-DNDEBUG"]

mkdir_p WASM_DIR
sh wasi_clang,
"--target=wasm32-wasip1",
# No `main`; the host calls `_initialize` and then the exported functions.
"-mexec-model=reactor",
"-std=gnu11",
"-O2",
*debug_flags,
"-Wno-unused-parameter",
"-I#{File.join(__dir__, "include")}",
"-o", WASM_OUTPUT,
Expand Down
5 changes: 5 additions & 0 deletions wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ $ rake wasm:install_jars # download the Chicory/ASM jars into ~/.m2 (run on JRub

The compiled `rbs_parser.wasm` is a build artifact and is not checked in.

Like the MRI extension, the module is compiled with `-DNDEBUG`, which removes the
`RBS_ASSERT` checks — they sit in the lexer and the constant pool, so leaving them
in costs around 20% of parse time. `DEBUG=1 rake wasm:build` keeps them, which is
what you want when debugging the parser itself through the module.

The WASI SDK is needed for the *build*, not for running the result — the host clang already
knows the `wasm32` target, but there is no wasm32 libc on a normal machine, so it picks up the
host headers and fails on the first `#include`. That is what the SDK supplies, along with the
Expand Down
Loading