Production-ready Bazel rules for building WebAssembly components across multiple languages with native WASI Preview 2 support.
- Multi-language: Build components from Rust, Go (TinyGo), C++, JavaScript/TypeScript
- Production Ready: OCI publishing, cryptographic signing, WAC composition, AOT compilation
- Bazel Native: Hermetic builds, aggressive caching, cross-platform (Windows/macOS/Linux)
- Zero Shell Scripts: Pure Bazel implementation for maximum portability
Add to your MODULE.bazel:
bazel_dep(name = "rules_wasm_component", version = "1.0.0")load("@rules_wasm_component//rust:defs.bzl", "rust_wasm_component")
rust_wasm_component(
name = "my_service",
srcs = ["src/lib.rs"],
wit = ":service_wit",
profiles = ["debug", "release"],
)load("@rules_wasm_component//go:defs.bzl", "go_wasm_component")
go_wasm_component(
name = "calculator",
srcs = ["main.go"],
wit = ":calculator_wit",
world = "calculator",
)load("@rules_wasm_component//cpp:defs.bzl", "cpp_component")
cpp_component(
name = "calculator",
srcs = ["calculator.cpp"],
wit = ":calculator_wit",
cxx_std = "c++20",
)load("@rules_wasm_component//wac:defs.bzl", "wac_compose")
wac_compose(
name = "full_system",
components = {
":frontend": "app:frontend",
":backend": "app:backend",
},
composition = '''
let frontend = new app:frontend { ... };
let backend = new app:backend { ... };
connect frontend.request -> backend.handler;
export frontend as main;
''',
)- Rust (1.90.0+): Multi-profile builds, Clippy integration, Wizer pre-initialization
- Go (TinyGo 0.39.0): Native WASI Preview 2, hermetic Go module resolution
- C++ (WASI SDK 27): C++17/20/23, cross-package headers, LTO optimization
- JavaScript/TypeScript (jco 1.4.0, Node.js 20.18.0): NPM dependencies, componentize-js
- WAC Composition: Official WebAssembly Composition standard for multi-component systems
- OCI Publishing: Push components to Docker/OCI registries
- Cryptographic Signing: wasmsign2 integration for supply chain security
- AOT Compilation: Wasmtime precompilation for 87% size reduction and faster startup
- Wizer Pre-initialization: 1.35-6x startup improvement for Rust components
- Multi-Profile Builds: Debug, release, and custom optimization profiles
- Hermetic Toolchains: All tools downloaded automatically, no system dependencies
- Cross-Platform: Native Windows/macOS/Linux support without WSL
- Bazel-First: Zero shell scripts, pure Bazel actions for reproducible builds
- Comprehensive Examples: 20+ working examples from basic to advanced patterns
See MODULE.bazel for current versions - the single source of truth.
All toolchains are hermetically downloaded and version-pinned for reproducible builds. Key toolchains include:
- wasm-tools - Component manipulation (new, validate, compose)
- TinyGo - Go β WASM compilation with WASI Preview 2
- WASI SDK - C/C++ β WASM compilation
- Wasmtime - WASM runtime and AOT compilation
- Wizer - Pre-initialization for faster startup
- wkg - Package management
- jco - JavaScript component compiler
π Complete Rule Reference - All rules, attributes, and providers
Guides:
- Toolchain Configuration
- Multi-Profile Builds
- Development Guidelines - Bazel-first principles
Examples:
- Basic Component - Getting started
- Multi-Language Composition - WAC composition
- Wizer Pre-initialization - Performance optimization
- OCI Publishing - Production deployment
- See all examples β
- Issue: WIT-enabled Go components currently fail due to upstream TinyGo limitations
- Tracking: GitHub Issue #82
- Status: Excluded from CI until TinyGo PR #4934 lands
- Workaround: Basic Go components (without WIT) work perfectly
- Design: WASI disables C++ exceptions by default for size/performance
- Solution: Components use error codes instead of exceptions (Issue #83)
- Override: Use
enable_exceptions = Truefor components that require exceptions
Contributions welcome! See CONTRIBUTING.md for details.
Apache 2.0 - See LICENSE for details.