Skip to content

Commit c5d76df

Browse files
committed
docs: fix terminology confusion between platform bindings and WebAssembly Component Model
Major terminology clarification to avoid confusion between our platform-specific bindings and the established WebAssembly Component Model guest/host terminology. Key changes: - Renamed guide from "Host vs WASM Bindings" to "Native vs Guest Bindings" - Fixed Mermaid diagram syntax errors and reduced visual complexity - Added clear explanation of WebAssembly Component Model terminology: * Host: Runtime environment (wasmtime, browser) executing components * Guest: WebAssembly component implementation running in host runtime * WIT: Interface definitions describing component interfaces Updated documentation to use consistent terminology: - "Native platform bindings" ({name}_bindings_host): For native development tools - "Guest component bindings" ({name}_bindings): For WebAssembly component implementations This resolves critical confusion where our "host bindings" conflicted with WebAssembly's "host runtime" terminology. The documentation now clearly distinguishes between: 1. Platform compilation targets (native vs wasm32-wasip2) 2. WebAssembly Component Model roles (host runtime vs guest component) Cross-references updated across troubleshooting guide and rule reference to maintain consistency and help developers understand the dual binding architecture without terminology conflicts.
1 parent d5b6506 commit c5d76df

File tree

4 files changed

+92
-71
lines changed

4 files changed

+92
-71
lines changed

docs-site/astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default defineConfig({
8282
{
8383
label: 'Guides',
8484
items: [
85-
{ label: 'Host vs WASM Bindings', slug: 'guides/host-vs-wasm-bindings' },
85+
{ label: 'Native vs Guest Bindings', slug: 'guides/host-vs-wasm-bindings' },
8686
{ label: 'Advanced Features', slug: 'guides/advanced-features' },
8787
{ label: 'Migration Guide', slug: 'guides/migration' },
8888
{ label: 'Toolchain Configuration', slug: 'guides/toolchain-configuration' },

docs-site/src/content/docs/guides/host-vs-wasm-bindings.mdx

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
11
---
2-
title: Host vs WASM Bindings
3-
description: Understanding when to use host-platform vs WASM-platform bindings for different development scenarios
2+
title: Native vs Guest Bindings
3+
description: Understanding when to use native platform bindings vs guest component bindings for different development scenarios
44
---
55

6-
# Host vs WASM Bindings
6+
# Native vs Guest Bindings
77

88
When you generate WIT bindings with `rust_wasm_component_bindgen`, you actually get **two different versions** of the same bindings compiled for different platforms. Understanding when to use each one is crucial for building effective WebAssembly component ecosystems.
99

10+
> **Important Terminology**: In the WebAssembly Component Model, "host" refers to the runtime executing components (like wasmtime), while "guest" refers to the component implementation. Our bindings use different terminology to avoid confusion.
11+
1012
## The Two Binding Types
1113

1214
```mermaid
13-
flowchart LR
15+
flowchart TD
1416
A[WIT Interface] --> B[Generated Rust Code]
15-
B --> C[Host Bindings<br/>{name}_bindings_host]
16-
B --> D[WASM Bindings<br/>{name}_bindings]
17+
B --> C[Native Platform Bindings<br/>name_bindings_host]
18+
B --> D[Guest Component Bindings<br/>name_bindings]
19+
20+
C --> E[Native Applications<br/>rust_binary, rust_test]
21+
D --> F[Guest Components<br/>Component Implementation]
1722
18-
C --> E[Host Applications<br/>rust_binary, rust_test]
19-
D --> F[WASM Components<br/>Component Implementation]
23+
G[Host Runtime<br/>wasmtime] --> F
2024
21-
style C fill:#e8f5e8,stroke:#4caf50,stroke-width:2px
22-
style D fill:#fff3e0,stroke:#f57c00,stroke-width:2px
23-
style E fill:#e8f5e8,stroke:#4caf50,stroke-width:2px
24-
style F fill:#fff3e0,stroke:#f57c00,stroke-width:2px
25+
style C fill:#e8f5e8,stroke:#4caf50
26+
style D fill:#fff3e0,stroke:#f57c00
27+
style E fill:#e8f5e8,stroke:#4caf50
28+
style F fill:#fff3e0,stroke:#f57c00
29+
style G fill:#e3f2fd,stroke:#1976d2
2530
```
2631

27-
### Host Bindings (`{name}_bindings_host`)
32+
### Native Platform Bindings (`{name}_bindings_host`)
2833

2934
**Target Platform**: Your development machine (e.g., `aarch64-apple-darwin`, `x86_64-unknown-linux-gnu`)
3035
**Runtime**: Native execution, no WebAssembly runtime required
31-
**Purpose**: Development tools, testing, benchmarking, host applications
36+
**Purpose**: Development tools, testing, benchmarking, native applications
37+
**Role**: Enables native programs to understand component interfaces
3238

33-
### WASM Bindings (`{name}_bindings`)
39+
### Guest Component Bindings (`{name}_bindings`)
3440

3541
**Target Platform**: WebAssembly (`wasm32-wasip2`)
3642
**Runtime**: WebAssembly runtime (wasmtime, web browsers, etc.)
37-
**Purpose**: Actual component implementations that run as WebAssembly
43+
**Purpose**: Actual component implementations compiled to WebAssembly
44+
**Role**: The "guest" that runs inside a "host" runtime like wasmtime
3845

3946
## Key Insight: Same Source, Different Targets
4047

@@ -48,20 +55,32 @@ wit_bindgen::generate!({
4855
});
4956

5057
// Compiled for two different targets:
51-
// 1. Host Platform (aarch64-apple-darwin) → {name}_bindings_host
52-
// 2. WASM Platform (wasm32-wasip2) → {name}_bindings
58+
// 1. Native Platform (aarch64-apple-darwin) → {name}_bindings_host
59+
// 2. Guest Platform (wasm32-wasip2) → {name}_bindings
5360
```
5461

55-
## When to Use Host Bindings
62+
## WebAssembly Component Model Context
63+
64+
To understand this architecture, it's important to know the WebAssembly Component Model terminology:
65+
66+
- **Host**: The runtime environment (wasmtime, browser, etc.) that executes WebAssembly components
67+
- **Guest**: The WebAssembly component implementation that runs inside the host
68+
- **WIT**: WebAssembly Interface Type definitions that describe component interfaces
69+
70+
Our binding system creates:
71+
- **Native platform bindings**: For native applications that need to understand component interfaces
72+
- **Guest component bindings**: For actual guest implementations that run in a host runtime
73+
74+
## When to Use Native Platform Bindings
5675

5776
Use `{name}_bindings_host` for:
5877

5978
### ✅ Test Applications
6079
```python
6180
rust_test(
62-
name = "component_integration_test",
81+
name = "component_integration_test",
6382
srcs = ["tests/integration.rs"],
64-
deps = [":calculator_bindings_host"], # Host bindings for tests
83+
deps = [":calculator_bindings_host"], # Native bindings for tests
6584
)
6685
```
6786

@@ -70,7 +89,7 @@ rust_test(
7089
rust_binary(
7190
name = "component_benchmark",
7291
srcs = ["bench/benchmark.rs"],
73-
deps = [":calculator_bindings_host"], # Host bindings for benchmarks
92+
deps = [":calculator_bindings_host"], # Native bindings for benchmarks
7493
)
7594
```
7695

@@ -79,13 +98,13 @@ rust_binary(
7998
rust_binary(
8099
name = "schema_validator",
81100
srcs = ["tools/validate.rs"],
82-
deps = [":calculator_bindings_host"], # Host bindings for tooling
101+
deps = [":calculator_bindings_host"], # Native bindings for tooling
83102
)
84103
```
85104

86105
### ✅ Mock Implementations
87106
```rust
88-
// In your test file
107+
// In your test file - runs natively, not in WebAssembly
89108
use calculator_bindings_host::exports::calculator::math::Guest;
90109

91110
struct MockCalculator;
@@ -96,13 +115,13 @@ impl Guest for MockCalculator {
96115
}
97116
```
98117

99-
## When to Use WASM Bindings
118+
## When to Use Guest Component Bindings
100119

101120
Use `{name}_bindings` for:
102121

103-
### ✅ Component Implementations
122+
### Guest Component Implementations
104123
```rust
105-
// Component source code (src/lib.rs)
124+
// Guest component source code (src/lib.rs) - compiles to WebAssembly
106125
use calculator_bindings::exports::calculator::math::Guest;
107126

108127
struct Calculator;
@@ -112,52 +131,52 @@ impl Guest for Calculator {
112131
}
113132
}
114133

115-
// Export the component
134+
// Export the guest component implementation
116135
calculator_bindings::export!(Calculator with_types_in calculator_bindings);
117136
```
118137

119138
This is automatically handled by `rust_wasm_component_bindgen`:
120139
```python
121140
rust_wasm_component_bindgen(
122141
name = "calculator",
123-
srcs = ["src/lib.rs"], # Uses calculator_bindings (WASM)
142+
srcs = ["src/lib.rs"], # Uses calculator_bindings (guest)
124143
wit = ":calculator_interfaces",
125144
)
126145
```
127146

128147
## Capabilities and Limitations
129148

130-
### Host Bindings Can Do
149+
### Native Platform Bindings Can Do
131150

132151
-**Run natively** on your development machine
133-
-**Access component interfaces** and type definitions
152+
-**Access component interfaces** and type definitions
134153
-**Import and use** WIT-generated traits and types
135154
-**Create mock implementations** for testing
136155
-**Build development tools** that understand component interfaces
137156
-**Serialize/deserialize** component data types
138157

139-
### Host Bindings Cannot Do
158+
### Native Platform Bindings Cannot Do
140159

141-
-**Run as WebAssembly components** in WASM runtimes
142-
-**Export component functions** to other languages
160+
-**Run as WebAssembly components** in host runtimes like wasmtime
161+
-**Export component functions** to other languages via WebAssembly
143162
-**Participate in WAC compositions** or component graphs
144163
-**Use WASI Preview 2** or component model features
145-
-**Be called by** JavaScript, Python, or other host languages
164+
-**Be executed by host runtimes** as guest components
146165

147-
### WASM Bindings Can Do
166+
### Guest Component Bindings Can Do
148167

149-
-**Run in WebAssembly runtimes** (wasmtime, browsers, etc.)
150-
-**Export component functions** to any language
168+
-**Run in host runtimes** (wasmtime, browsers, etc.)
169+
-**Export component functions** to any language via WebAssembly
151170
-**Participate in component compositions** via WAC
152171
-**Use WASI Preview 2** filesystem, networking, etc.
153-
-**Be distributed** via OCI registries
172+
-**Be distributed** via OCI registries
154173
-**Provide secure sandboxing** and portability
155174

156-
### WASM Bindings Cannot Do
175+
### Guest Component Bindings Cannot Do
157176

158-
-**Run natively** on host platforms
159-
-**Be used directly** in host applications
160-
-**Access host system resources** outside WASI
177+
-**Run natively** on native platforms
178+
-**Be used directly** in native applications
179+
-**Access native system resources** outside WASI sandbox
161180

162181
## Common Error and Solution
163182

@@ -170,19 +189,19 @@ note: the following crate versions were found:
170189
```
171190
172191
### The Problem
173-
You're trying to use WASM-platform bindings (`my_component_bindings`) in a host application that expects host-platform target triples.
192+
You're trying to use guest component bindings (`my_component_bindings`) in a native application that expects native platform target triples.
174193

175194
### The Solution
176-
Use host-platform bindings instead:
195+
Use native platform bindings instead:
177196

178197
```python
179-
# ❌ Wrong: Host application using WASM bindings
198+
# ❌ Wrong: Native application using guest bindings
180199
rust_binary(
181200
name = "test_runner",
182201
deps = [":my_component_bindings"], # wasm32-wasip2 target
183202
)
184203
185-
# ✅ Correct: Host application using host bindings
204+
# ✅ Correct: Native application using native bindings
186205
rust_binary(
187206
name = "test_runner",
188207
deps = [":my_component_bindings_host"], # aarch64-apple-darwin target
@@ -303,17 +322,19 @@ rust_wasm_component_test(
303322
304323
### 4. Development Workflow
305324
1. **Design**: Define WIT interfaces
306-
2. **Implement**: Create component with WASM bindings
307-
3. **Test**: Build test tools with host bindings
308-
4. **Deploy**: Distribute WASM components
325+
2. **Implement**: Create guest components with guest bindings
326+
3. **Test**: Build test tools with native bindings
327+
4. **Deploy**: Distribute guest components to host runtimes
309328
310329
## Summary
311330
312-
Host and WASM bindings enable a rich development ecosystem around WebAssembly components:
331+
Native and guest bindings enable a rich development ecosystem around WebAssembly components:
313332
314-
- **Host bindings** provide native access to component interfaces for development tools
315-
- **WASM bindings** enable actual component execution in WebAssembly runtimes
333+
- **Native platform bindings** provide native access to component interfaces for development tools
334+
- **Guest component bindings** enable actual component execution in WebAssembly host runtimes
316335
- **Both are generated** from the same WIT interfaces, ensuring consistency
317-
- **Choose based on context**: host applications use host bindings, components use WASM bindings
336+
- **Choose based on context**: native applications use native bindings, guest components use guest bindings
337+
338+
This dual binding architecture resolves target triple mismatches while enabling powerful tooling and testing capabilities for WebAssembly component development.
318339
319-
This dual binding architecture resolves target triple mismatches while enabling powerful tooling and testing capabilities for WebAssembly component development.
340+
> **Key Takeaway**: Don't confuse our "host bindings" (native platform) with the WebAssembly Component Model "host runtime" (wasmtime). They serve different purposes in the ecosystem.

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ rust_wasm_component(
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

230230
**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
231+
- `{name}_bindings_host`: Native platform rust_library for native applications (e.g., test runners, benchmarks)
232+
- `{name}_bindings`: Guest component rust_library for WebAssembly components
233+
- `{name}`: The final guest component
234234

235-
> **📖 Deep Dive:** For detailed guidance on when to use host vs WASM bindings, see [Host vs WASM Bindings Guide](/guides/host-vs-wasm-bindings/).
235+
> **📖 Deep Dive:** For detailed guidance on when to use native vs guest bindings, see [Native vs Guest Bindings Guide](/guides/host-vs-wasm-bindings/).
236236
237237
**Load from:**
238238
```python
@@ -276,26 +276,26 @@ rust_wasm_component_bindgen(
276276
)
277277
```
278278

279-
#### Host applications using component bindings
279+
#### Native applications using component bindings
280280

281-
When building host applications that need to use component bindings (e.g., for testing or benchmarking), use the `*_bindings_host` target:
281+
When building native applications that need to use component bindings (e.g., for testing or benchmarking), use the `*_bindings_host` target:
282282

283283
```python
284284
rust_binary(
285285
name = "component_test_runner",
286286
srcs = ["tests/runner.rs"],
287-
deps = [":my_component_bindings_host"], # Host bindings for host app
287+
deps = [":my_component_bindings_host"], # Native bindings for native app
288288
)
289289

290-
# The component implementation uses WASM bindings automatically
290+
# The component implementation uses guest bindings automatically
291291
rust_wasm_component_bindgen(
292292
name = "my_component",
293-
srcs = ["src/lib.rs"], # Uses my_component_bindings (WASM platform)
293+
srcs = ["src/lib.rs"], # Uses my_component_bindings (guest platform)
294294
wit = ":my_interfaces",
295295
)
296296
```
297297

298-
> **📖 Complete Guide:** See [Host vs WASM Bindings](/guides/host-vs-wasm-bindings/) for detailed examples and use cases.
298+
> **📖 Complete Guide:** See [Native vs Guest Bindings](/guides/host-vs-wasm-bindings/) for detailed examples and use cases.
299299
300300
### rust_wasm_component_test
301301

docs-site/src/content/docs/troubleshooting/common-issues.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,25 @@ note: the following crate versions were found:
139139
crate 'my_component_bindings', target triple wasm32-wasip2
140140
```
141141

142-
**Cause**: You're using WASM-platform bindings (`my_component_bindings`) in a host application that expects host-platform target triples.
142+
**Cause**: You're using guest component bindings (`my_component_bindings`) in a native application that expects native platform target triples.
143143

144-
**Solution**: Use host-platform bindings for host applications:
144+
**Solution**: Use native platform bindings for native applications:
145145

146146
```python
147-
# ❌ Wrong: Host application using WASM bindings
147+
# ❌ Wrong: Native application using guest bindings
148148
rust_binary(
149149
name = "test_runner",
150150
deps = [":my_component_bindings"], # wasm32-wasip2 target
151151
)
152152

153-
# ✅ Correct: Host application using host bindings
153+
# ✅ Correct: Native application using native bindings
154154
rust_binary(
155155
name = "test_runner",
156156
deps = [":my_component_bindings_host"], # aarch64-apple-darwin target
157157
)
158158
```
159159

160-
**Learn more**: [Host vs WASM Bindings Guide](/guides/host-vs-wasm-bindings/)
160+
**Learn more**: [Native vs Guest Bindings Guide](/guides/host-vs-wasm-bindings/)
161161

162162
---
163163

0 commit comments

Comments
 (0)