ruby-rbs-sys: support wasm32 targets#2992
Open
rubys wants to merge 1 commit into
Open
Conversation
Compile the vendored RBS C parser to wasm with the WASI SDK's clang (via WASI_SDK_PATH), and generate the FFI bindings against the host target (--target=$HOST, layout_tests off) rather than the wasm target. Running bindgen against the wasm target is libclang-version-fragile: some libclangs drop all function declarations, others emit the forward-referenced node structs (rbs_namespace, rbs_type_name, rbs_ast_symbol, ...) as opaque, which breaks the generated layout assertions. The emitted #[repr(C)] declarations are layout-portable, so generating them for the host and compiling them for wasm32 is both correct and reliable. Mirrors ruby-prism-sys's wasm build support. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bf7872d to
5bf71cb
Compare
rubys
added a commit
to rubys/roundhouse
that referenced
this pull request
Jun 14, 2026
…er spike Drop the rubys/rbs-rust fork: roundhouse now depends on the published ruby-rbs = "0.3" on every target. wasm only needs ruby-rbs-sys built for wasm32 — its vendored RBS C parser compiled by the WASI-SDK clang, and its bindgen run against the host target (#[repr(C)] is layout-portable), sidestepping the libclang-version-fragile bindgen-against-wasm failures. That build.rs support is upstreamed as ruby/rbs#2992; until it publishes, wasm/Cargo.toml carries a temporary [patch.crates-io] ruby-rbs-sys local path (repin once merged). Build requires WASI_SDK_PATH=/opt/wasi-sdk. Also lands the rung-A Phase 0 browser spike (wasm/browser-spike/): a shared wasi-shim.mjs + transpile.mjs driving both the Node validator and a static browser page — proving the compiler transpiles real-blog in a real tab with no WebContainer/npm/bundler. Plus docs/browser-demo-plan.md. Verified: native cargo check --lib clean; wasm build clean (3.2 MB); node round-trip OK. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rubys
added a commit
to rubys/roundhouse
that referenced
this pull request
Jun 14, 2026
Make wasm/playground/ self-contained so it deploys as a static dir: vendor the C-ABI driver (transpile.mjs + wasi-shim.mjs) and check in the prebuilt compiler roundhouse_wasm.wasm (3.2 MB) + a seed fixture.json; playground.js now imports/fetches from ./ instead of ../browser-spike/. Add a build-site CI step that bundles _site/playground/ (copies the dir, regenerates fixture.json from the freshly-built real-blog so the editor's seed app tracks create-blog), mirroring how /blog/ is assembled. Link it from the landing page and the demo page. The compiler wasm is checked in, NOT built in CI: a runner build needs the WASI SDK + a published ruby-rbs-sys (upstream-pending as ruby/rbs#2992). Rather than block on that, the binary is committed and refreshed by hand on compiler/emit changes (see wasm/playground/README.md). Switch to a CI build + drop the binary once #2992 lands. Documented in docs/browser-demo-plan.md (new 'Publishing to Pages' section). Verified: self-contained playground and the CI-assembled bundle both pass verify-playground.mjs (Playwright); ci.yml is valid YAML. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Teach
ruby-rbs-sys's build script to supportwasm32-*targets:WASI_SDK_PATH).--target=$HOST,layout_tests(false)) rather than the wasm target.This mirrors
ruby-prism-sys's existing wasm build support.Why
Running bindgen against the wasm target is libclang-version-fragile. Across libclangs I see two distinct failures, both on
wasm32-wasip1:rbs_*function declarations;rbs_namespace,rbs_type_name,rbs_ast_symbol,rbs_types_block,rbs_ast_declarations_class_super) as opaque, so the generated layout assertions overflow (E0080).The generated
#[repr(C)]declarations are layout-portable, so generating them for the host and compiling them forwasm32is both correct and reliable. The C parser is still compiled for wasm by the WASI SDK clang.Testing
cargo build -p ruby-rbs-sys --target wasm32-wasip1andcargo build -p ruby-rbs --target wasm32-wasip1both succeed.rbs_parser_new→rbs_parse_signature→ walkingsignature.declarations(and the high-levelruby_rbs::node::parse) runs correctly under a WASI runtime.🤖 Generated with Claude Code