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
- 🐹 Go Integration: TinyGo v0.38.0 with WASI Preview 2 component support
- 🔧 Toolchain Management: Automatic wasm-tools and wit-bindgen setup
- 📦 Composition: WAC-based component composition with OCI registry support
- 🐳 OCI Publishing: Publish and distribute components via container registries
- 🔐 Digital Signing: Component signing with wasmsign2 and verification
- 🏗️ Enterprise Architecture: Multi-registry microservices with security policies
- 🎯 Type Safety: Strongly typed WIT interfaces
- ⚡ Performance: Optimized builds with proper caching
Add to your MODULE.bazel
:
bazel_dep(name = "rules_wasm_component", version = "1.0.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
)
# Optional: Configure TinyGo toolchain version
tinygo = use_extension("//wasm:extensions.bzl", "tinygo")
tinygo.register(
name = "tinygo",
tinygo_version = "0.38.0" # Optional, defaults to 0.38.0
)
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 = ":my_interfaces",
deps = [
"//third_party/rust:wit_bindgen",
],
)
load("@rules_wasm_component//go:defs.bzl", "go_wasm_component")
go_wasm_component(
name = "my_go_component",
srcs = ["main.go", "logic.go"],
wit = "my-interface.wit",
world = "my-world",
go_mod = "go.mod",
adapter = "//wasm/adapters:wasi_snapshot_preview1",
)
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
go_wasm_component
- Build Go WASM components with TinyGogo_wit_bindgen
- Generate Go bindings from WIT interfaces
wac_compose
- Compose multiple componentswac_compose_with_oci
- Compose local and OCI registry componentswac_microservices_app
- Microservices composition patternwac_distributed_system
- Distributed system composition patternwasm_component_new
- Convert modules to components
wasm_component_oci_image
- Prepare OCI images for componentswasm_component_publish
- Publish components to registrieswasm_component_from_oci
- Pull components from OCI registrieswkg_registry_config
- Configure registry authenticationwkg_multi_registry_publish
- Publish to multiple registries
wasm_keygen
- Generate signing key pairswasm_sign
- Sign WebAssembly componentswasm_security_policy
- Define security policieswasm_component_secure_publish
- Policy-enforced publishing
wasm_validate
- Validate WASM componentswit_lint
- Lint WIT interfaces
See the examples/
directory for complete examples:
- Basic Component - Simple component with WIT
- Go Component - TinyGo WASM components
- JavaScript Component - JS components with ComponentizeJS
- C++ Component - Native C++ component development
- WAC Remote Compose - Remote component composition
- WAC + OCI Composition - OCI registry integration
- Microservices Architecture - Production-ready microservices
- Multi-Language Composition - Polyglot component systems
- OCI Publishing - Container registry publishing
- Component Signing - Digital signatures with wasmsign2
- Wizer Pre-initialization - Startup optimization
- Wasmtime Runtime - Custom runtime integration
- Multi-Profile Components - Development vs production builds
- 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.
This project uses pre-commit hooks for code quality:
# Install pre-commit
pip install pre-commit
# Install hooks
pre-commit install
pre-commit install --hook-type commit-msg
# Test setup
pre-commit run --all-files
See Pre-commit Instructions for detailed setup.
Apache 2.0 - See LICENSE for details.