Skip to content

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Jan 24, 2026

Summary

Adds a new moonbit_wasm_cli rule that generates WASI bindings using wit-bindgen moonbit, enabling MoonBit code to use proper WASI interfaces (stdout, stderr, environment, etc.) instead of MoonBit's spectest-based I/O.

Key Features

  • Full WASI support pipeline: wit-bindgen → stub replacement → moon build → wasm-tools embed/new
  • Uses cli_wit directly: Properly handles wit_library directory output
  • Correct package imports: Adds stdout/streams imports to the run package
  • Working example: //examples/moonbit_component:hello_wasi

Changes

  • moonbit/private/moonbit_wasm_cli.bzl - New rule implementation
  • moonbit/defs.bzl - Export new rule
  • examples/moonbit_component/hello_wasi.mbt - Working example
  • MODULE.bazel - Made rules_moonbit a regular dependency (not dev_dependency)
  • .bazelversion - Pin to Bazel 8.2.1 for wasi_sdk compatibility
  • checksums/tools/componentize-py.json - Updated checksums for canary

Usage

load("@rules_wasm_component//moonbit:defs.bzl", "moonbit_wasm_cli")

moonbit_wasm_cli(
    name = "my_cli",
    srcs = ["main.mbt"],
)

User's MoonBit code must implement run():

pub fn run() -> Result[Unit, Unit] {
  let stdout = @stdout.get_stdout()
  let bytes = string_to_bytes("Hello!\n")
  match stdout.blocking_write_and_flush(bytes) {
    Ok(_) => Ok(())
    Err(_) => Err(())
  }
}

Test plan

  • Build //examples/moonbit_component:hello_wasi
  • Run with wasmtime - outputs "Hello from MoonBit WASI CLI!"
  • Verified checksum_updater project can use the rule

avrabe and others added 4 commits January 24, 2026 17:26
Add checksums for wit-bindgen 0.51.0 release (2026-01-12).
This version includes native MoonBit binding generation support.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds a new rule that generates WASI bindings using wit-bindgen moonbit,
enabling MoonBit code to use proper WASI interfaces (stdout, stderr, etc.)
instead of MoonBit's spectest-based I/O.

Key changes:
- moonbit_wasm_cli rule with full WASI support pipeline
- Uses cli_wit directory directly from wit_library
- Replaces generated stub with user implementation
- Adds proper package imports for stdout/streams

Also includes:
- Bazel 8.2.1 version pin for wasi_sdk compatibility
- Updated componentize-py checksums for canary release
- Made rules_moonbit a regular dependency (not dev_dependency)
- Working hello_wasi example
@avrabe avrabe force-pushed the feature/moonbit-component-support branch from a55793e to 2356de8 Compare January 24, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants