Skip to content

Commit 4752d54

Browse files
authored
Merge pull request #3066 from ruby/claude/wasm-ndebug-build-ytf7tz
Build the wasm module with -DNDEBUG
2 parents 915b54f + 84f4fc2 commit 4752d54

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,13 +926,20 @@ namespace :wasm do
926926

927927
desc "Build the RBS parser as a WebAssembly module (requires WASI_SDK_PATH)"
928928
task :build do
929+
# `-DNDEBUG` compiles out `RBS_ASSERT`, the same way ext/rbs_extension does
930+
# for the MRI extension. The assertions sit in the lexer and the constant
931+
# pool, so keeping them costs about 20% of parse time; set `DEBUG=1` to keep
932+
# them when debugging the module itself.
933+
debug_flags = ENV["DEBUG"] ? [] : ["-DNDEBUG"]
934+
929935
mkdir_p WASM_DIR
930936
sh wasi_clang,
931937
"--target=wasm32-wasip1",
932938
# No `main`; the host calls `_initialize` and then the exported functions.
933939
"-mexec-model=reactor",
934940
"-std=gnu11",
935941
"-O2",
942+
*debug_flags,
936943
"-Wno-unused-parameter",
937944
"-I#{File.join(__dir__, "include")}",
938945
"-o", WASM_OUTPUT,

wasm/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ $ rake wasm:install_jars # download the Chicory/ASM jars into ~/.m2 (run on JRub
2727

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

30+
Like the MRI extension, the module is compiled with `-DNDEBUG`, which removes the
31+
`RBS_ASSERT` checks — they sit in the lexer and the constant pool, so leaving them
32+
in costs around 20% of parse time. `DEBUG=1 rake wasm:build` keeps them, which is
33+
what you want when debugging the parser itself through the module.
34+
3035
The WASI SDK is needed for the *build*, not for running the result — the host clang already
3136
knows the `wasm32` target, but there is no wasm32 libc on a normal machine, so it picks up the
3237
host headers and fails on the first `#include`. That is what the SDK supplies, along with the

0 commit comments

Comments
 (0)