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).
//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. Userust_componentfor 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. Usec_componentfor 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-gois 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 minimalgo.modfile to emulate a Go module. This is a lower-level rule that you normally wouldn't need to use directly. Usego_componentfor a single macro to compile a component from Go.
See example/.
- Currently works only for the following execution platforms
(due to the use of Bash scripts and downloading pre-built tool binaries):
aarch64-linuxaarch64-macosx86_64-linuxx86_64-macos