Build the RBS parser as a WebAssembly module (JRuby support, step 1)#2998
Open
soutaro wants to merge 1 commit into
Open
Build the RBS parser as a WebAssembly module (JRuby support, step 1)#2998soutaro wants to merge 1 commit into
soutaro wants to merge 1 commit into
Conversation
The parser under src/ is plain, self-contained C with no dependency on the Ruby C API, so it can be compiled to WebAssembly as-is. This is the foundation for running RBS on Ruby implementations that cannot load the MRI C extension (notably JRuby). - Add wasm/rbs_wasm.c: a reactor-model entry shim exposing a small, stable ABI (alloc/free, parse_signature, and a selftest). - Add `rake wasm:build` and `rake wasm:check` tasks driven by the WASI SDK (WASI_SDK_PATH) and wasmtime. - Add a WebAssembly CI workflow that builds and smoke-tests the module. - Drop unused <sys/mman.h>/<fcntl.h>/<sys/types.h> includes from rbs_allocator.c (only sysconf() is used) so the arena allocator compiles cleanly against wasi-libc. Serializing the parsed AST back to the host and wiring this into RBS on JRuby come in follow-up steps. https://claude.ai/code/session_01LTveMt3NLbYHEboXuzAKpA
This was referenced Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
This is the first step toward running RBS on Ruby implementations that cannot load the MRI C extension — notably JRuby — using WebAssembly instead of an FFI/dylib.
The parser under
src/is plain, self-contained C with no dependency on the Ruby C API, so it can be compiled to WebAssembly as-is. The plan is to compile the parser to a.wasmmodule, run it on a JVM WebAssembly runtime under JRuby, and reconstructRBS::ASTobjects on the Ruby side.Plan (split into PRs)
src/*.ctowasm32-wasip1, expose a minimal stable ABI, build it from Rake, and smoke-test it in CI.config.yml, alongside the existingast_translation.c) plus a pure-Ruby deserializer. Validated on CRuby first via a round-trip against the existing C → Ruby translation, so the hardest part is de-risked without any WASM involved.rbs_parser.wasmwith Chicory (a pure-JVM WASM runtime, zero native deps), run the serializer entry point, feed the result to the step-2 deserializer, and branchlib/rbs.rbonRUBY_ENGINE. Adds a JRuby CI job.(Runtime = Chicory, format = compact binary — confirmed up front.)
What this PR does
wasm/rbs_wasm.c— a reactor-model entry shim exposing a small, stable ABI:rbs_wasm_alloc(i32) -> i32rbs_wasm_free(i32) -> ()rbs_wasm_allocrbs_wasm_parse_signature(i32 ptr, i32 len) -> i32rbs_wasm_selftest() -> i32rake wasm:build/rake wasm:check— driven by the WASI SDK (WASI_SDK_PATH) and wasmtime (WASMTIME)..github/workflows/wasm.yml— installs the WASI SDK + wasmtime and runsrake wasm:check.src/util/rbs_allocator.c— drop unused<sys/mman.h>/<fcntl.h>/<sys/types.h>includes (onlysysconf()is used) so the arena allocator compiles cleanly against wasi-libc. WASI has nommap, and the code never called it; this is the only change needed to the shared C source.No AST is serialized back to the host yet — that's step 2.
Testing
Verified locally with wasi-sdk-33 (clang 22) and wasmtime 45:
Also confirmed:
rbs_wasm_selftestreturns0; malformed RBS →1;test/rbs/parser_test.rbpasses (42 tests, 395 assertions, 0 failures) after therbs_allocator.cchange.The compiled
rbs_parser.wasmis a build artifact and is gitignored.https://claude.ai/code/session_01LTveMt3NLbYHEboXuzAKpA
Generated by Claude Code