Skip to content

Commit 46ca964

Browse files
committed
fix: expose host-platform bindings to resolve Rust target triple mismatch
The rust_wasm_component_bindgen rule was creating both host-platform and WASM-platform binding libraries, but only the WASM-platform version was publicly accessible. This caused host applications (like test runners and benchmarks) to attempt using WASM-platform bindings, resulting in target triple mismatch errors when the host platform expected x86_64-unknown-linux-gnu or aarch64-apple-darwin but received wasm32-wasip2. Changes: - Make {name}_bindings_host targets publicly visible for host applications - Update test/export_macro to use host bindings for rust_binary target - Add comprehensive documentation explaining when to use host vs WASM bindings - Update rule reference with usage examples and generated target explanations The solution implements a dual binding architecture: - {name}_bindings_host: Host-platform rust_library for host applications - {name}_bindings: WASM-platform rust_library for component implementations - {name}: Final WASM component This resolves issue #16 while maintaining clean separation between host and WASM platform concerns. Host applications can now properly consume component bindings without target triple conflicts.
1 parent a1daa8c commit 46ca964

File tree

8 files changed

+1259
-6
lines changed

8 files changed

+1259
-6
lines changed

docs-site/astro.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export default defineConfig({
4848
{
4949
label: 'Getting Started',
5050
items: [
51+
{ label: 'Learning Path', slug: 'learning-path' },
52+
{ label: 'Zero to Component in 2 Minutes', slug: 'zero-to-component' },
5153
{ label: 'Quick Start', slug: 'getting-started' },
5254
{ label: 'Installation', slug: 'installation' },
5355
{ label: 'First Component', slug: 'first-component' },
@@ -63,6 +65,7 @@ export default defineConfig({
6365
{
6466
label: 'Tutorials',
6567
items: [
68+
{ label: 'Code Explained Line by Line', slug: 'tutorials/code-explained' },
6669
{ label: 'Guided Rust Walkthrough', slug: 'tutorials/rust-guided-walkthrough' },
6770
{ label: 'Guided Go (TinyGo) Walkthrough', slug: 'tutorials/go-guided-walkthrough' },
6871
],
@@ -123,6 +126,7 @@ export default defineConfig({
123126
{
124127
label: 'Troubleshooting',
125128
items: [
129+
{ label: 'Common Issues & Solutions', slug: 'troubleshooting/common-issues' },
126130
{ label: 'Export Macro Visibility', slug: 'troubleshooting/export-macro-visibility' },
127131
],
128132
},
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: Learning Path
3+
description: A progressive guide through WebAssembly component development
4+
---
5+
6+
# Learning Path
7+
8+
This guide provides a structured path through our documentation, from complete beginner to advanced WebAssembly component developer. Follow the path that matches your experience level and goals.
9+
10+
## 🚀 Path 1: Complete Beginner
11+
*"I'm new to WebAssembly and want to see it working quickly"*
12+
13+
### Step 1: Get Something Working Fast ⚡
14+
**Goal**: See a working component in under 2 minutes
15+
- **[Zero to Component in 2 Minutes](/zero-to-component/)**
16+
- **Time**: 2 minutes
17+
- **What you'll get**: A working WebAssembly component + basic understanding
18+
19+
### Step 2: Understand What You Built 🧠
20+
**Goal**: Understand every line of code
21+
- **[Code Explained Line by Line](/tutorials/code-explained/)**
22+
- **Time**: 10 minutes
23+
- **What you'll learn**: Deep understanding of WIT, BUILD.bazel, and Rust code
24+
25+
### Step 3: Build Your Own 🔨
26+
**Goal**: Create your first component from scratch
27+
- **[First Component](/first-component/)**
28+
- **Time**: 15 minutes
29+
- **What you'll learn**: Project setup, troubleshooting, testing
30+
31+
### Step 4: Handle Problems 🐛
32+
**Goal**: Fix common issues confidently
33+
- **[Common Issues & Solutions](/troubleshooting/common-issues/)**
34+
- **Time**: 5 minutes reading (save for when needed)
35+
- **What you'll learn**: Debugging skills, common pitfalls
36+
37+
**🎓 Graduation**: You can now build basic WebAssembly components!
38+
39+
---
40+
41+
## 💻 Path 2: Experienced Developer
42+
*"I know programming but am new to WebAssembly/Bazel"*
43+
44+
### Step 1: Quick Start + Concepts ⚡
45+
**Goal**: Get oriented with WebAssembly components
46+
- **[Quick Start](/getting-started/)** - Full overview
47+
- **[Architecture Overview](/architecture/overview/)** - Understand the ecosystem
48+
- **Time**: 15 minutes
49+
50+
### Step 2: Complete Tutorial 🎯
51+
**Goal**: Build something substantial with explanations
52+
- **[Guided Rust Walkthrough](/tutorials/rust-guided-walkthrough/)**
53+
- **Time**: 30 minutes
54+
- **What you'll learn**: Complete development workflow, best practices
55+
56+
### Step 3: Try Different Languages 🌍
57+
**Goal**: See how components work across languages
58+
- **[Go Components](/languages/go/)** - TinyGo approach
59+
- **[C++ Components](/languages/cpp/)** - Native development
60+
- **[JavaScript Components](/languages/javascript/)** - Web ecosystem
61+
- **Time**: 15 minutes each
62+
63+
### Step 4: Advanced Features 🚀
64+
**Goal**: Learn production-ready features
65+
- **[Component Composition](/composition/wac/)** - Multi-component systems
66+
- **[Performance Optimization](/production/performance/)** - Wizer pre-initialization
67+
- **Time**: 20 minutes each
68+
69+
**🎓 Graduation**: You can build production WebAssembly systems!
70+
71+
---
72+
73+
## 🏗️ Path 3: Building Real Applications
74+
*"I want to build something for production"*
75+
76+
### Step 1: Choose Your Stack 🎯
77+
**Goal**: Pick the right language and approach
78+
79+
**For Web Applications:**
80+
- **[JavaScript Components](/languages/javascript/)** - Best for web integration
81+
- **[WAC Composition](/composition/wac/)** - Frontend + backend components
82+
83+
**For System Services:**
84+
- **[Rust Components](/languages/rust/)** - Best performance and ecosystem
85+
- **[Go Components](/languages/go/)** - Familiar syntax, good concurrency
86+
87+
**For Legacy Integration:**
88+
- **[C++ Components](/languages/cpp/)** - Port existing C/C++ code
89+
90+
### Step 2: Study Real Examples 📚
91+
**Goal**: See complete implementations
92+
- **[Calculator (C++)](/examples/calculator/)** - Error handling patterns
93+
- **[HTTP Service (Go)](/examples/http-service/)** - Web service architecture
94+
- **[Multi-Language System](/examples/multi-language/)** - Polyglot composition
95+
- **Time**: 10 minutes each
96+
97+
### Step 3: Production Setup 🏭
98+
**Goal**: Deploy securely and efficiently
99+
- **[Toolchain Configuration](/guides/toolchain-configuration/)** - CI/CD setup
100+
- **[Component Signing](/security/component-signing/)** - Security practices
101+
- **[OCI Publishing](/production/publishing/)** - Distribution strategy
102+
- **Time**: 30 minutes total
103+
104+
### Step 4: Advanced Architecture 🎨
105+
**Goal**: Design scalable systems
106+
- **[WRPC Communication](/reference/rules/#rpc-communication)** - Remote procedure calls
107+
- **[WAC + OCI Integration](/composition/wac-oci-integration/)** - Distributed components
108+
- **[Performance Optimization](/production/performance/)** - Production tuning
109+
- **Time**: 45 minutes total
110+
111+
**🎓 Graduation**: You can architect and deploy WebAssembly component systems!
112+
113+
---
114+
115+
## 🔬 Path 4: Advanced Developer/Contributor
116+
*"I want to extend the toolchain or contribute"*
117+
118+
### Step 1: Understand the Architecture 🏗️
119+
**Goal**: Deep understanding of the build system
120+
- **[Development Workflow](/workflow/development-flow/)** - Internal processes
121+
- **[Toolchain Configuration](/guides/toolchain-configuration/)** - Advanced customization
122+
- **[Migration Guide](/guides/migration/)** - Bazel best practices
123+
124+
### Step 2: Master All Rules 📖
125+
**Goal**: Complete reference knowledge
126+
- **[Rule Reference](/reference/rules/)** - All 31 rules and providers
127+
- **[Advanced Examples](/examples/advanced-examples/)** - Complex scenarios
128+
- Study the source code in `/examples`
129+
130+
### Step 3: Extended Features 🚀
131+
**Goal**: Use cutting-edge capabilities
132+
- **[Multi-Profile Builds](/guides/multi-profile-builds/)** - Advanced build configurations
133+
- **[External WIT Dependencies](/guides/external-wit-dependencies/)** - WASI ecosystem
134+
- **[Enterprise Security](/security/)** - Advanced security patterns
135+
136+
**🎓 Graduation**: You can extend and contribute to the ecosystem!
137+
138+
---
139+
140+
## 📚 Reference Materials
141+
142+
### Quick References
143+
- **[Rule Reference](/reference/rules/)** - Complete rule documentation
144+
- **[Common Issues](/troubleshooting/common-issues/)** - Debug guide
145+
- **[Installation](/installation/)** - Setup instructions
146+
147+
### Example Library
148+
- **[Basic Examples](/examples/basic-examples/)** - Simple patterns
149+
- **[Intermediate Examples](/examples/intermediate-examples/)** - Common use cases
150+
- **[Advanced Examples](/examples/advanced-examples/)** - Complex scenarios
151+
152+
### Language-Specific Guides
153+
- **[Rust](/languages/rust/)** - Best practices, patterns, optimization
154+
- **[Go](/languages/go/)** - TinyGo specifics, WASI Preview 2
155+
- **[C++](/languages/cpp/)** - WASI SDK, native development
156+
- **[JavaScript](/languages/javascript/)** - ComponentizeJS, npm integration
157+
158+
---
159+
160+
## 🎯 Choose Your Next Step
161+
162+
**New to WebAssembly?** → Start with [Zero to Component in 2 Minutes](/zero-to-component/)
163+
164+
**Want to understand the code?** → Read [Code Explained Line by Line](/tutorials/code-explained/)
165+
166+
**Ready to build something real?** → Try [Calculator Example](/examples/calculator/)
167+
168+
**Need help with an error?** → Check [Common Issues](/troubleshooting/common-issues/)
169+
170+
**Want to see all capabilities?** → Browse [Rule Reference](/reference/rules/)
171+
172+
Remember: The best way to learn is by building! Start with something simple, get it working, then gradually add complexity. 🚀

docs-site/src/content/docs/reference/rules.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ rust_wasm_component(
227227

228228
Builds a Rust WebAssembly component with WIT binding generation. Compiles Rust source code into a WASM component and generates language bindings from WIT interfaces.
229229

230+
**Generated Targets:**
231+
- `{name}_bindings_host`: Host-platform rust_library for host applications (e.g., test runners, benchmarks)
232+
- `{name}_bindings`: WASM-platform rust_library for WASM components
233+
- `{name}`: The final WASM component
234+
230235
**Load from:**
231236
```python
232237
load("@rules_wasm_component//rust:defs.bzl", "rust_wasm_component_bindgen")
@@ -269,6 +274,25 @@ rust_wasm_component_bindgen(
269274
)
270275
```
271276

277+
#### Host applications using component bindings
278+
279+
When building host applications that need to use component bindings (e.g., for testing or benchmarking), use the `*_bindings_host` target:
280+
281+
```python
282+
rust_binary(
283+
name = "component_test_runner",
284+
srcs = ["tests/runner.rs"],
285+
deps = [":my_component_bindings_host"], # Host bindings for host app
286+
)
287+
288+
# The component implementation uses WASM bindings
289+
rust_wasm_component_bindgen(
290+
name = "my_component",
291+
srcs = ["src/lib.rs"], # Uses my_component_bindings (WASM platform)
292+
wit = ":my_interfaces",
293+
)
294+
```
295+
272296
### rust_wasm_component_test
273297

274298
Tests a Rust WASM component using wasmtime runtime. Provides automated testing for WebAssembly components.

0 commit comments

Comments
 (0)