Modern Bazel rules for building and composing WebAssembly components.
- 🚀 Component Model Support: Full support for WASM Component Model and WIT
- 🦀 Rust Integration: Seamless integration with rules_rust
- 🔧 Toolchain Management: Automatic wasm-tools and wit-bindgen setup
- 📦 Composition: WAC-based component composition
- 🎯 Type Safety: Strongly typed WIT interfaces
- ⚡ Performance: Optimized builds with proper caching
Add to your MODULE.bazel
:
bazel_dep(name = "rules_wasm_component", version = "0.1.0")
# Optional: Configure WASM toolchain version
wasm_toolchain = use_extension(
"@rules_wasm_component//wasm:extensions.bzl",
"wasm_toolchain",
)
wasm_toolchain.register(
name = "wasm_tools",
version = "1.0.60", # Optional, defaults to latest stable
)
load("@rules_wasm_component//wit:defs.bzl", "wit_library")
wit_library(
name = "my_interfaces",
srcs = ["my-interface.wit"],
deps = ["//wit/deps:wasi-io"],
)
load("@rules_wasm_component//rust:defs.bzl", "rust_wasm_component")
rust_wasm_component(
name = "my_component",
srcs = ["src/lib.rs"],
wit_bindgen = ":my_interfaces",
deps = [
"//third_party/rust:wit_bindgen",
],
)
load("@rules_wasm_component//wac:defs.bzl", "wac_compose")
wac_compose(
name = "my_system",
components = {
"frontend": ":frontend_component",
"backend": ":backend_component",
},
composition = """
let frontend = new frontend:component { ... };
let backend = new backend:component { ... };
connect frontend.request -> backend.handler;
export frontend as main;
""",
)
wit_library
- Process WIT interface fileswit_bindgen
- Generate language bindings from WIT
rust_wasm_component
- Build Rust WASM componentsrust_wasm_component_test
- Test WASM components
wac_compose
- Compose multiple componentswasm_component_new
- Convert modules to components
wasm_validate
- Validate WASM componentswit_lint
- Lint WIT interfaces
See the examples/
directory for complete examples:
- Basic Component - Simple component with WIT
- Composition - Multi-component system
- WASI Integration - Using WASI interfaces
- Testing - Component testing patterns
- AI Agent Guide - Structured documentation for AI coding assistants
- Rule Schemas - Machine-readable rule definitions
- Examples - Progressive complexity examples:
- Basic - Fundamental patterns
- Intermediate - Cross-package dependencies
- Advanced - Complex compositions and custom rules
Contributions are welcome! Please read our Contributing Guide.
Apache 2.0 - See LICENSE for details.