| 
1 | 1 | # Bazel Rules for WebAssembly Component Model  | 
2 | 2 | 
 
  | 
3 |  | -Modern Bazel rules for building and composing WebAssembly components.  | 
 | 3 | +Modern Bazel rules for building WebAssembly components across multiple languages.  | 
4 | 4 | 
 
  | 
5 |  | -## Features  | 
 | 5 | +## Why Use This?  | 
6 | 6 | 
 
  | 
7 |  | -- 🚀 **Component Model Support**: Full support for WASM Component Model and WIT  | 
8 |  | -- 🦀 **Rust Integration**: Seamless integration with rules_rust  | 
9 |  | -- 🐹 **Go Integration**: TinyGo v0.38.0 with WASI Preview 2 component support  | 
10 |  | -- 🔧 **Toolchain Management**: Automatic wasm-tools and wit-bindgen setup  | 
11 |  | -- 📦 **Composition**: WAC-based component composition with OCI registry support  | 
12 |  | -- 🐳 **OCI Publishing**: Publish and distribute components via container registries  | 
13 |  | -- 🔐 **Digital Signing**: Component signing with wasmsign2 and verification  | 
14 |  | -- 🏗️ **Enterprise Architecture**: Multi-registry microservices with security policies  | 
15 |  | -- 🎯 **Type Safety**: Strongly typed WIT interfaces  | 
16 |  | -- ⚡ **Performance**: Optimized builds with proper caching  | 
 | 7 | +- **Multi-language**: Build components from Rust, Go, C++, JavaScript  | 
 | 8 | +- **Production Ready**: OCI publishing, signing, composition, optimization    | 
 | 9 | +- **Bazel Native**: Hermetic builds, caching, cross-platform support  | 
17 | 10 | 
 
  | 
18 | 11 | ## Installation  | 
19 | 12 | 
 
  | 
20 | 13 | Add to your `MODULE.bazel`:  | 
21 | 14 | 
 
  | 
22 | 15 | ```starlark  | 
23 | 16 | bazel_dep(name = "rules_wasm_component", version = "1.0.0")  | 
24 |  | - | 
25 |  | -# Optional: Configure WASM toolchain version  | 
26 |  | -wasm_toolchain = use_extension(  | 
27 |  | -    "@rules_wasm_component//wasm:extensions.bzl",  | 
28 |  | -    "wasm_toolchain",  | 
29 |  | -)  | 
30 |  | -wasm_toolchain.register(  | 
31 |  | -    name = "wasm_tools",  | 
32 |  | -    version = "1.0.60",  # Optional, defaults to latest stable  | 
33 |  | -)  | 
34 |  | - | 
35 |  | -# Optional: Configure TinyGo toolchain version  | 
36 |  | -tinygo = use_extension("//wasm:extensions.bzl", "tinygo")  | 
37 |  | -tinygo.register(  | 
38 |  | -    name = "tinygo",  | 
39 |  | -    tinygo_version = "0.38.0"  # Optional, defaults to 0.38.0  | 
40 |  | -)  | 
41 |  | -```  | 
42 |  | - | 
43 |  | -## Quick Start  | 
44 |  | - | 
45 |  | -### 1. Define WIT Interfaces  | 
46 |  | - | 
47 |  | -```starlark  | 
48 |  | -load("@rules_wasm_component//wit:defs.bzl", "wit_library")  | 
49 |  | - | 
50 |  | -wit_library(  | 
51 |  | -    name = "my_interfaces",  | 
52 |  | -    srcs = ["my-interface.wit"],  | 
53 |  | -    deps = ["//wit/deps:wasi-io"],  | 
54 |  | -)  | 
55 | 17 | ```  | 
56 | 18 | 
 
  | 
57 |  | -### 2. Build Rust WASM Component  | 
 | 19 | +## Quick Example  | 
58 | 20 | 
 
  | 
59 | 21 | ```starlark  | 
60 |  | -load("@rules_wasm_component//rust:defs.bzl", "rust_wasm_component")  | 
61 |  | - | 
62 |  | -rust_wasm_component(  | 
63 |  | -    name = "my_component",  | 
 | 22 | +# Build a component from Rust  | 
 | 23 | +rust_wasm_component_bindgen(  | 
 | 24 | +    name = "hello_component",   | 
64 | 25 |     srcs = ["src/lib.rs"],  | 
65 |  | -    wit = ":my_interfaces",  | 
66 |  | -    deps = [  | 
67 |  | -        "//third_party/rust:wit_bindgen",  | 
68 |  | -    ],  | 
 | 26 | +    wit = ":hello_interfaces",  | 
69 | 27 | )  | 
70 | 28 | ```  | 
71 | 29 | 
 
  | 
72 |  | -### 2b. Build Go WASM Component  | 
73 |  | - | 
74 |  | -```starlark  | 
75 |  | -load("@rules_wasm_component//go:defs.bzl", "go_wasm_component")  | 
76 |  | - | 
77 |  | -go_wasm_component(  | 
78 |  | -    name = "my_go_component",  | 
79 |  | -    srcs = ["main.go", "logic.go"],  | 
80 |  | -    wit = "my-interface.wit",  | 
81 |  | -    world = "my-world",  | 
82 |  | -    go_mod = "go.mod",  | 
83 |  | -    adapter = "//wasm/adapters:wasi_snapshot_preview1",  | 
84 |  | -)  | 
85 |  | -```  | 
86 |  | - | 
87 |  | -### 3. Compose Components  | 
88 |  | - | 
89 |  | -```starlark  | 
90 |  | -load("@rules_wasm_component//wac:defs.bzl", "wac_compose")  | 
91 |  | - | 
92 |  | -wac_compose(  | 
93 |  | -    name = "my_system",  | 
94 |  | -    components = {  | 
95 |  | -        "frontend": ":frontend_component",  | 
96 |  | -        "backend": ":backend_component",  | 
97 |  | -    },  | 
98 |  | -    composition = """  | 
99 |  | -        let frontend = new frontend:component { ... };  | 
100 |  | -        let backend = new backend:component { ... };  | 
101 |  | -
  | 
102 |  | -        connect frontend.request -> backend.handler;  | 
103 |  | -
  | 
104 |  | -        export frontend as main;  | 
105 |  | -    """,  | 
106 |  | -)  | 
107 |  | -```  | 
108 |  | - | 
109 |  | -## Rules  | 
110 |  | - | 
111 |  | -### WIT Rules  | 
112 |  | - | 
113 |  | -- `wit_library` - Process WIT interface files  | 
114 |  | -- `wit_bindgen` - Generate language bindings from WIT  | 
115 |  | - | 
116 |  | -### Rust Rules  | 
117 |  | - | 
118 |  | -- `rust_wasm_component` - Build Rust WASM components  | 
119 |  | -- `rust_wasm_component_test` - Test WASM components  | 
120 |  | - | 
121 |  | -### Go Rules  | 
122 |  | - | 
123 |  | -- `go_wasm_component` - Build Go WASM components with TinyGo  | 
124 |  | -- `go_wit_bindgen` - Generate Go bindings from WIT interfaces  | 
125 |  | - | 
126 |  | -### Composition Rules  | 
127 |  | - | 
128 |  | -- `wac_compose` - Compose multiple components  | 
129 |  | -- `wac_compose_with_oci` - Compose local and OCI registry components  | 
130 |  | -- `wac_microservices_app` - Microservices composition pattern  | 
131 |  | -- `wac_distributed_system` - Distributed system composition pattern  | 
132 |  | -- `wasm_component_new` - Convert modules to components  | 
133 |  | - | 
134 |  | -### OCI Publishing Rules  | 
135 |  | - | 
136 |  | -- `wasm_component_oci_image` - Prepare OCI images for components  | 
137 |  | -- `wasm_component_publish` - Publish components to registries  | 
138 |  | -- `wasm_component_from_oci` - Pull components from OCI registries  | 
139 |  | -- `wkg_registry_config` - Configure registry authentication  | 
140 |  | -- `wkg_multi_registry_publish` - Publish to multiple registries  | 
141 |  | - | 
142 |  | -### Security Rules  | 
143 |  | - | 
144 |  | -- `wasm_keygen` - Generate signing key pairs  | 
145 |  | -- `wasm_sign` - Sign WebAssembly components  | 
146 |  | -- `wasm_security_policy` - Define security policies  | 
147 |  | -- `wasm_component_secure_publish` - Policy-enforced publishing  | 
148 |  | - | 
149 |  | -### Analysis Rules  | 
150 |  | - | 
151 |  | -- `wasm_validate` - Validate WASM components  | 
152 |  | -- `wit_lint` - Lint WIT interfaces  | 
153 |  | - | 
154 |  | -## Examples  | 
155 |  | - | 
156 |  | -See the [`examples/`](examples/) directory for complete examples:  | 
157 |  | - | 
158 |  | -### Core Examples  | 
159 |  | - | 
160 |  | -- [Basic Component](examples/basic/) - Simple component with WIT  | 
161 |  | -- [Go Component](examples/go_component/) - TinyGo WASM components  | 
162 |  | -- [JavaScript Component](examples/js_component/) - JS components with ComponentizeJS  | 
163 |  | -- [C++ Component](examples/cpp_component/) - Native C++ component development  | 
164 |  | - | 
165 |  | -### Composition and Architecture  | 
166 |  | - | 
167 |  | -- [WAC Remote Compose](examples/wac_remote_compose/) - Remote component composition  | 
168 |  | -- [WAC + OCI Composition](examples/wac_oci_composition/) - OCI registry integration  | 
169 |  | -- [Microservices Architecture](examples/microservices_architecture/) - Production-ready microservices  | 
170 |  | -- [Multi-Language Composition](examples/multi_language_composition/) - Polyglot component systems  | 
171 |  | - | 
172 |  | -### OCI and Distribution  | 
173 |  | - | 
174 |  | -- [OCI Publishing](examples/oci_publishing/) - Container registry publishing  | 
175 |  | -- [Component Signing](examples/wasm_signing/) - Digital signatures with wasmsign2  | 
176 |  | - | 
177 |  | -### Advanced Features  | 
178 |  | - | 
179 |  | -- [Wizer Pre-initialization](examples/wizer_example/) - Startup optimization  | 
180 |  | -- [Wasmtime Runtime](examples/wasmtime_runtime/) - Custom runtime integration  | 
181 |  | -- [Multi-Profile Components](examples/multi_profile/) - Development vs production builds  | 
182 |  | - | 
183 | 30 | ## Documentation  | 
184 | 31 | 
 
  | 
185 |  | -### For Developers  | 
186 |  | - | 
187 |  | -- [Rule Reference](docs/rules.md)  | 
188 |  | -- [Migration Guide](docs/migration.md)  | 
189 |  | -- [Best Practices](docs/best_practices.md)  | 
190 |  | -- [Troubleshooting](docs/troubleshooting.md)  | 
191 |  | - | 
192 |  | -### For AI Agents  | 
 | 32 | +📚 **[Complete Documentation →](https://github.com/pulseengine/rules_wasm_component/tree/main/docs-site)**  | 
193 | 33 | 
 
  | 
194 |  | -- [**AI Agent Guide**](docs/ai_agent_guide.md) - Structured documentation for AI coding assistants  | 
195 |  | -- [**Rule Schemas**](docs/rule_schemas.json) - Machine-readable rule definitions  | 
196 |  | -- [Examples](docs/examples/) - Progressive complexity examples:  | 
197 |  | -  - [Basic](docs/examples/basic/) - Fundamental patterns  | 
198 |  | -  - [Intermediate](docs/examples/intermediate/) - Cross-package dependencies  | 
199 |  | -  - [Advanced](docs/examples/advanced/) - Complex compositions and custom rules  | 
 | 34 | +- **[Zero to Component in 2 Minutes](/docs-site/src/content/docs/zero-to-component.mdx)** - Fastest way to get started  | 
 | 35 | +- **[Language Guides](/docs-site/src/content/docs/languages/)** - Rust, Go, C++, JavaScript tutorials    | 
 | 36 | +- **[Production Deployment](/docs-site/src/content/docs/production/)** - OCI publishing, signing, optimization  | 
 | 37 | +- **[Examples](examples/)** - Working examples from basic to advanced  | 
200 | 38 | 
 
  | 
201 | 39 | ## Contributing  | 
202 | 40 | 
 
  | 
203 |  | -Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md).  | 
204 |  | - | 
205 |  | -### Development Setup  | 
206 |  | - | 
207 |  | -This project uses pre-commit hooks for code quality:  | 
208 |  | - | 
209 |  | -```bash  | 
210 |  | -# Install pre-commit  | 
211 |  | -pip install pre-commit  | 
212 |  | - | 
213 |  | -# Install hooks  | 
214 |  | -pre-commit install  | 
215 |  | -pre-commit install --hook-type commit-msg  | 
216 |  | - | 
217 |  | -# Test setup  | 
218 |  | -pre-commit run --all-files  | 
219 |  | -```  | 
220 |  | - | 
221 |  | -See [Pre-commit Instructions](.pre-commit-instructions.md) for detailed setup.  | 
 | 41 | +Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for details.  | 
222 | 42 | 
 
  | 
223 | 43 | ## License  | 
224 | 44 | 
 
  | 
 | 
0 commit comments