Skip to content

Commit d5b6506

Browse files
committed
docs: add comprehensive guide on host vs WASM bindings
Added new documentation to clarify the dual binding architecture and resolve confusion around target triple mismatches. This addresses the core concepts behind the fix for issue #16. Key additions: - New guide: "Host vs WASM Bindings" with complete examples and use cases - Added to sidebar navigation for easy discovery - Cross-references from rule reference and troubleshooting docs - Visual diagrams showing the binding architecture - Practical examples of when to use each binding type The guide explains: - How the same WIT-generated code creates two binding types - Target platform differences (host vs wasm32-wasip2) - Capabilities and limitations of each binding type - Common errors and solutions - Best practices for development workflows This ensures developers understand when to use: - {name}_bindings_host: For test runners, benchmarks, development tools - {name}_bindings: For actual component implementations Resolves documentation gaps around the host vs WASM binding architecture.
1 parent 46ca964 commit d5b6506

23 files changed

+754
-311
lines changed

docs-site/CONTENT_HIERARCHY.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Documentation Content Hierarchy
2+
3+
## Purpose
4+
5+
This document defines the clear content hierarchy for the docs-site to prevent duplication and ensure proper cross-referencing between pages.
6+
7+
## Content Ownership Structure
8+
9+
### 1. Installation & Setup (Canonical Sources)
10+
11+
**Primary owner:** `/installation.md`
12+
- Complete installation instructions for all platforms
13+
- All language-specific setup (Rust, Go, C++, JavaScript)
14+
- Toolchain configuration details
15+
- Troubleshooting installation issues
16+
17+
**Secondary references:**
18+
- `/getting-started.mdx` - Quick reference with link to full installation
19+
- `/first-component.md` - Minimal setup with reference to installation guide
20+
- Language-specific guides - Link to installation for setup details
21+
22+
**Pattern:** Other pages should provide minimal setup and reference `/installation.md` for details.
23+
24+
### 2. Tutorial Progression (Learning Path)
25+
26+
**Ultra-fast (2 min):** `/zero-to-component.mdx`
27+
- Immediate success using existing examples
28+
- Minimal explanation, maximum speed
29+
- References detailed tutorials for understanding
30+
31+
**Quick hands-on (10 min):** `/first-component.md`
32+
- Build from scratch step-by-step
33+
- Focused on practical implementation
34+
- References installation and detailed tutorials
35+
36+
**Complete understanding (30 min):** `/tutorials/rust-guided-walkthrough.mdx`
37+
- Deep explanations of concepts and pipeline
38+
- Line-by-line code analysis with diagrams
39+
- Complete mental model building
40+
41+
**Technical reference:** `/tutorials/code-explained.mdx`
42+
- Visual diagrams of component building process
43+
- Progressive complexity with Mermaid diagrams
44+
- Technical deep-dive into each file
45+
46+
### 3. Code Examples (Canonical Patterns)
47+
48+
**BUILD.bazel patterns:**
49+
- **Owner:** `/examples/basic/` - Canonical Rust component pattern
50+
- **Owner:** `/examples/calculator/` - Error handling pattern
51+
- **Owner:** Language-specific examples - Language-specific patterns
52+
53+
**References:**
54+
- Tutorial pages link to examples instead of duplicating BUILD.bazel code
55+
- Rule reference shows usage patterns, examples show complete implementations
56+
57+
**WIT interface examples:**
58+
- **Owner:** `/tutorials/code-explained.mdx` - Detailed WIT explanations
59+
- **References:** Other pages link to detailed explanations rather than re-explaining
60+
61+
### 4. Advanced Topics (Specialized Ownership)
62+
63+
**Component Composition:**
64+
- **Owner:** `/composition/wac/` - Complete WAC composition guide
65+
- **References:** Getting started mentions composition, links to dedicated guide
66+
67+
**Performance Optimization:**
68+
- **Owner:** `/production/performance/` - Wizer and optimization techniques
69+
- **References:** Other pages mention performance, link to dedicated guide
70+
71+
**Security & Signing:**
72+
- **Owner:** `/security/component-signing.mdx` - Complete security guide
73+
- **References:** Brief mentions in other pages, links for details
74+
75+
### 5. Language-Specific Content
76+
77+
**Rust:** `/languages/rust/`
78+
**Go:** `/languages/go/`
79+
**C++:** `/languages/cpp/`
80+
**JavaScript:** `/languages/javascript/`
81+
82+
**Pattern:** Each language guide owns its specific patterns and advanced features. Getting started provides overview, language guides provide depth.
83+
84+
### 6. Reference Documentation
85+
86+
**Rule Reference:** `/reference/rules.mdx`
87+
- **Owner:** Complete API documentation for all rules
88+
- **Pattern:** Examples show usage, reference shows complete API
89+
90+
**Troubleshooting:** `/troubleshooting/common-issues.mdx`
91+
- **Owner:** All error messages and solutions
92+
- **Pattern:** Other pages reference troubleshooting for specific issues
93+
94+
## Content Cross-Reference Patterns
95+
96+
### ✅ Good Patterns
97+
98+
1. **Provide minimal context + link to canonical source**
99+
```markdown
100+
For complete installation instructions, see the [Installation Guide](/installation/).
101+
102+
Quick setup for Rust:
103+
[minimal code example]
104+
```
105+
106+
2. **Use approach grids for different learning paths**
107+
```html
108+
<div class="approach-grid">
109+
<div class="approach-card">
110+
<h3>🚀 Ultra-Fast (2 minutes)</h3>
111+
<p>Get working instantly</p>
112+
<a href="/zero-to-component/">Zero to Component →</a>
113+
</div>
114+
</div>
115+
```
116+
117+
3. **Reference examples instead of duplicating BUILD.bazel**
118+
```markdown
119+
For the complete BUILD.bazel pattern, see the [basic example](/examples/basic/).
120+
```
121+
122+
### ❌ Anti-Patterns to Avoid
123+
124+
1. **Duplicating installation instructions**
125+
- ❌ Copy full MODULE.bazel setup across multiple pages
126+
- ✅ Provide minimal setup + link to installation guide
127+
128+
2. **Re-explaining WIT syntax**
129+
- ❌ Explain WIT syntax on every tutorial page
130+
- ✅ Link to detailed explanation in code-explained tutorial
131+
132+
3. **Duplicating BUILD.bazel examples**
133+
- ❌ Show complete BUILD.bazel on multiple pages
134+
- ✅ Show pattern summary + link to complete example
135+
136+
4. **Redundant troubleshooting**
137+
- ❌ Scatter error solutions across multiple pages
138+
- ✅ Centralize in troubleshooting guide + cross-reference
139+
140+
## Content Update Protocol
141+
142+
### When Adding New Content
143+
144+
1. **Check existing hierarchy** - Does this content fit an existing owner?
145+
2. **Identify content type** - Tutorial, reference, example, or specialized guide?
146+
3. **Assign ownership** - Which page should be the canonical source?
147+
4. **Plan references** - How will other pages reference this content?
148+
149+
### When Updating Existing Content
150+
151+
1. **Identify the canonical owner** - Update the source of truth first
152+
2. **Update references** - Ensure cross-references remain accurate
153+
3. **Check for duplication** - Remove any content that duplicates the update
154+
155+
### Review Checklist
156+
157+
Before publishing content changes:
158+
159+
- [ ] Is this content duplicated elsewhere?
160+
- [ ] Does this page properly reference canonical sources?
161+
- [ ] Are cross-references accurate and helpful?
162+
- [ ] Does this follow the established content hierarchy?
163+
- [ ] Would a new user understand the learning progression?
164+
165+
## Maintenance
166+
167+
This hierarchy should be reviewed quarterly to:
168+
- Identify new duplication that has crept in
169+
- Update reference patterns as content evolves
170+
- Ensure learning paths remain clear and progressive
171+
- Consolidate content that has become scattered
172+
173+
## Success Metrics
174+
175+
- **No content duplication** - Same information shouldn't exist in multiple places
176+
- **Clear learning paths** - Users can progress from beginner to advanced
177+
- **Fast answers** - Users can quickly find what they need
178+
- **Cross-references work** - Links lead to the right level of detail
179+
180+
This hierarchy ensures our documentation grows systematically while remaining maintainable and user-friendly.

docs-site/astro.config.mjs

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

docs-site/docs_build.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _docs_build_impl(ctx):
5656
# Install dependencies using hermetic npm (from PATH via tools)
5757
npm install --no-audit --no-fund
5858
59-
# Build documentation site
59+
# Build documentation site (rule docs should be pre-generated)
6060
npm run build
6161
6262
# Return to execution root and create output file there

docs-site/scripts/generate-rule-docs.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const SCHEMA_GENERATOR_TARGET = '//tools/generate_schemas:generate_schemas';
2323
* Generate fresh schema JSON from Bazel
2424
*/
2525
function generateSchemaJson() {
26-
console.log('🔧 Generating fresh rule schemas from Bazel...');
26+
console.log('Generating fresh rule schemas from Bazel...');
2727

2828
try {
2929
const result = execSync(`cd "${REPO_ROOT}" && bazel run ${SCHEMA_GENERATOR_TARGET}`, {
@@ -33,7 +33,7 @@ function generateSchemaJson() {
3333

3434
return JSON.parse(result);
3535
} catch (error) {
36-
console.error('Failed to generate schemas:', error.message);
36+
console.error('Failed to generate schemas:', error.message);
3737

3838
// Fallback: try to use existing schema file
3939
const fallbackPath = path.join(REPO_ROOT, 'docs/rule_schemas.json');
@@ -252,12 +252,12 @@ function generateRuleReference(schemas) {
252252
* Main execution
253253
*/
254254
function main() {
255-
console.log('📚 Generating Rule Reference Documentation...');
255+
console.log('Generating Rule Reference Documentation...');
256256

257257
try {
258258
// Generate schema JSON
259259
const schemas = generateSchemaJson();
260-
console.log(`Loaded ${Object.keys(schemas).length} rule definitions`);
260+
console.log(`Loaded ${Object.keys(schemas).length} rule definitions`);
261261

262262
// Generate markdown
263263
const markdown = generateRuleReference(schemas);
@@ -271,11 +271,11 @@ function main() {
271271
const outputPath = path.join(DOCS_OUTPUT_DIR, 'rules.mdx');
272272
fs.writeFileSync(outputPath, markdown, 'utf-8');
273273

274-
console.log(`📖 Generated rule reference: ${outputPath}`);
275-
console.log(`📊 Documented ${Object.keys(schemas).length} rules and providers`);
274+
console.log(`Generated rule reference: ${outputPath}`);
275+
console.log(`Documented ${Object.keys(schemas).length} rules and providers`);
276276

277277
} catch (error) {
278-
console.error('Error generating documentation:', error.message);
278+
console.error('Error generating documentation:', error.message);
279279
process.exit(1);
280280
}
281281
}

docs-site/src/content/docs/composition/wac.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ wac_compose(
9090
)
9191
```
9292

93+
> **📋 Rule Reference:** For complete details on composition rule attributes, see [`wac_compose`](/reference/rules/#wac_compose) and [`wac_remote_compose`](/reference/rules/#wac_remote_compose).
94+
9395
### Component Interface Definitions
9496

9597
Define interfaces that allow composition:

docs-site/src/content/docs/first-component.md

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,23 @@ mkdir -p src wit
4141
touch BUILD.bazel MODULE.bazel Cargo.toml src/lib.rs wit/greeting.wit
4242
```
4343

44-
## Step 2: Configure Bazel Module
44+
## Step 2: Configure Your Project
4545

46-
Set up your `MODULE.bazel`:
46+
Set up your project dependencies. For detailed installation instructions and advanced configuration options, see the [Installation Guide](/installation/).
47+
48+
**Quick setup for Rust components:**
4749

4850
```python title="MODULE.bazel"
49-
module(
50-
name = "my_first_component",
51-
version = "0.1.0",
52-
)
51+
module(name = "my_first_component", version = "0.1.0")
5352

54-
# Add rules_wasm_component
5553
bazel_dep(name = "rules_wasm_component", version = "1.0.0")
5654
bazel_dep(name = "rules_rust", version = "0.48.0")
5755

58-
# Configure crate dependencies
5956
crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
60-
crate.from_cargo(
61-
name = "crates",
62-
cargo_lockfile = "//:Cargo.lock",
63-
manifests = ["//:Cargo.toml"],
64-
)
57+
crate.from_cargo(name = "crates", cargo_lockfile = "//:Cargo.lock", manifests = ["//:Cargo.toml"])
6558
use_repo(crate, "crates")
6659
```
6760

68-
## Step 3: Set Up Rust Dependencies
69-
70-
Create your `Cargo.toml`:
71-
7261
```toml title="Cargo.toml"
7362
[package]
7463
name = "my-first-component"
@@ -82,13 +71,11 @@ wit-bindgen = { version = "0.30.0", default-features = false, features = ["reall
8271
crate-type = ["cdylib"]
8372
```
8473

85-
Generate the lock file:
86-
8774
```bash
8875
cargo generate-lockfile
8976
```
9077

91-
## Step 4: Define the WIT Interface
78+
## Step 3: Define the WIT Interface
9279

9380
Create your component interface in `wit/greeting.wit`:
9481

@@ -112,7 +99,7 @@ world greeting-component {
11299
}
113100
```
114101

115-
## Step 5: Configure the Build
102+
## Step 4: Configure the Build
116103

117104
Set up your `BUILD.bazel`:
118105

@@ -141,7 +128,9 @@ rust_wasm_component_test(
141128
)
142129
```
143130

144-
## Step 6: Implement the Component
131+
> **📋 Rule Reference:** For complete details on all rule attributes and options, see [`wit_library`](/reference/rules/#wit_library), [`rust_wasm_component_bindgen`](/reference/rules/#rust_wasm_component_bindgen), and [`rust_wasm_component_test`](/reference/rules/#rust_wasm_component_test).
132+
133+
## Step 5: Implement the Component
145134

146135
Create your Rust implementation in `src/lib.rs`:
147136

@@ -174,7 +163,7 @@ impl Guest for GreetingComponent {
174163
let count = GREETING_COUNTER.fetch_add(1, Ordering::SeqCst) + 1;
175164

176165
// Generate personalized greeting
177-
format!("Hello, {}! This is greeting #{} 👋", name, count)
166+
format!("Hello, {}! This is greeting #{}", name, count)
178167
}
179168

180169
fn random_greeting() -> String {
@@ -184,7 +173,7 @@ impl Guest for GreetingComponent {
184173
// Simple pseudo-random selection based on counter
185174
let greeting = GREETINGS[count as usize % GREETINGS.len()];
186175

187-
format!("{}, friend! 🎉", greeting)
176+
format!("{}, friend!", greeting)
188177
}
189178

190179
fn greeting_count() -> u32 {
@@ -196,7 +185,7 @@ impl Guest for GreetingComponent {
196185
greeting_component_bindings::export!(GreetingComponent with_types_in greeting_component_bindings);
197186
```
198187

199-
## Step 7: Build Your Component
188+
## Step 6: Build Your Component
200189

201190
Now build your component with Bazel:
202191

@@ -215,7 +204,7 @@ If the build succeeds, you'll see output like:
215204
INFO: Build completed successfully, 15 total actions
216205
```
217206

218-
## Step 8: Test Your Component
207+
## Step 7: Test Your Component
219208

220209
Run the automated tests:
221210

@@ -227,7 +216,7 @@ bazel test //:greeting_test
227216
# //:greeting_test PASSED in 1.2s
228217
```
229218

230-
## Step 9: Inspect Your Component
219+
## Step 8: Inspect Your Component
231220

232221
Examine the generated WebAssembly component:
233222

@@ -242,7 +231,7 @@ wasm-tools validate bazel-bin/greeting_component.wasm --features component-model
242231
ls -lh bazel-bin/greeting_component.wasm
243232
```
244233

245-
## Step 10: Run Your Component
234+
## Step 9: Run Your Component
246235

247236
If you have wasmtime installed, you can run your component:
248237

@@ -253,10 +242,10 @@ wasmtime run --wasi preview2 bazel-bin/greeting_component.wasm
253242

254243
<div class="demo-buttons">
255244
<a href="https://stackblitz.com/github/pulseengine/rules_wasm_component/tree/main/examples/basic" class="demo-button">
256-
🚀 Try this tutorial in StackBlitz
245+
Try this tutorial in StackBlitz
257246
</a>
258247
<a href="https://github.com/codespaces/new?repo=pulseengine/rules_wasm_component" class="demo-button">
259-
☁️ Open in GitHub Codespace
248+
Open in GitHub Codespace
260249
</a>
261250
</div>
262251

0 commit comments

Comments
 (0)