rules_wasm
v1.0.6
published 10 months ago
4 stars
0 forks
1 watchers
MIT No Attribution
public
0 assets
Maintained byWill Noble
v1.0.6
October 1, 2024
[expand for release notes]

WebAssembly Component Bazel Tools

A Bazel module with tools for working with WebAssembly components.

This module primarily hosts language-agnostic rules for working with WebAssembly components, but also welcomes language-specific rules to compile source code files into components (including generating WIT bindings).

Rules

  • //wasm:defs.bzl:
    • wasm_component - Turn a core Wasm module into a component.
    • wasm_plug - Link the exports of a 'plug' component into the imports of a 'wrapper' component to create a new component. This is the simplest way to compose components together without a WAC file.
    • wit_package - Bundle a group of WIT files into a unified package.
  • //rust:defs.bzl:
    • rust_component - Compile a Wasm interface and matching Rust implementation into a Wasm component.
    • rust_wit_bindgen - Generate Rust sources for a Wasm interface. This is a lower-level rule that you normally wouldn't need to use directly. Use rust_component for a single macro to compile a component from Rust.
  • C support is hacky and needs to be adapted to a proper CC toolchain (blocked on bazelbuild/rules_cc#277), but there's //c:defs.bzl, which makes use of the WASI SDK:
    • c_component - Compile a Wasm interface and matching C implementation into a Wasm component.
    • c_wit_bindgen - Generate C sources for a Wasm interface. This is a lower-level rule that you normally wouldn't need to use directly. Use c_component for a single macro to compile a component from C.
  • Go support is hacky and needs to be adapted to a proper Go toolchain. This is fundamentally difficult because Bazel's Go rules require knowing about module metadata and dependencies during the analysis phase, but the output of wit-bindgen-go is only known for sure during the execution phase. Meanwhile, there's a temporary crutch: //go:defs.bzl, which makes use of TinyGo and is somewhat limited.
    • go_component - Compile a Wasm interface and matching C implementation into a Wasm component.
    • go_wit_bindgen - Generate Go sources for a Wasm interface, including a minimal go.mod file to emulate a Go module. This is a lower-level rule that you normally wouldn't need to use directly. Use go_component for a single macro to compile a component from Go.

Examples

See example/.

Caveats

  • Currently works only for the following execution platforms (due to the use of Bash scripts and downloading pre-built tool binaries):
    • aarch64-linux
    • aarch64-macos
    • x86_64-linux
    • x86_64-macos