|
| 1 | +# Cookbook: Building Wasm Components for Wassette |
| 2 | + |
| 3 | +Welcome to the Wassette Cookbook! This section provides practical guides and recipes for building WebAssembly (Wasm) components that work with Wassette from various programming languages. |
| 4 | + |
| 5 | +## What You'll Learn |
| 6 | + |
| 7 | +The cookbook guides will walk you through: |
| 8 | + |
| 9 | +- Setting up your development environment for each language |
| 10 | +- Understanding WebAssembly Interface Types (WIT) |
| 11 | +- Creating component interfaces |
| 12 | +- Implementing component logic |
| 13 | +- Building and testing your components |
| 14 | +- Best practices and common patterns |
| 15 | + |
| 16 | +## Available Language Guides |
| 17 | + |
| 18 | +Choose the programming language you want to use to build your Wasm component: |
| 19 | + |
| 20 | +### [JavaScript/TypeScript](./javascript.md) |
| 21 | +Build Wasm components using JavaScript or TypeScript with the Bytecode Alliance's `jco` tooling. Perfect for developers familiar with Node.js ecosystem. |
| 22 | + |
| 23 | +**Key highlights:** |
| 24 | +- Use familiar JavaScript/TypeScript syntax |
| 25 | +- Leverage npm packages and existing JavaScript libraries |
| 26 | +- Quick build times with `jco componentize` |
| 27 | +- Examples: time server, weather API, data processing |
| 28 | + |
| 29 | +### [Python](./python.md) |
| 30 | +Create Wasm components using Python with `componentize-py`. Ideal for data processing, scripting, and AI/ML workflows. |
| 31 | + |
| 32 | +**Key highlights:** |
| 33 | +- Write components in pure Python |
| 34 | +- Use the `uv` package manager for fast builds |
| 35 | +- Access Python's rich ecosystem |
| 36 | +- Examples: calculator, code execution, data analysis |
| 37 | + |
| 38 | +### [Rust](./rust.md) |
| 39 | +Build high-performance Wasm components with Rust. Best for performance-critical tools and system-level programming. |
| 40 | + |
| 41 | +**Key highlights:** |
| 42 | +- Near-native performance |
| 43 | +- Strong type safety and memory safety |
| 44 | +- Extensive WebAssembly tooling support |
| 45 | +- Examples: file system operations, HTTP clients |
| 46 | + |
| 47 | +### [Go](./go.md) |
| 48 | +Develop Wasm components using Go and TinyGo. Great for developers who prefer Go's simplicity and concurrency features. |
| 49 | + |
| 50 | +**Key highlights:** |
| 51 | +- Familiar Go syntax and idioms |
| 52 | +- Good performance characteristics |
| 53 | +- Growing WebAssembly support |
| 54 | +- Examples: module information service |
| 55 | + |
| 56 | +## Getting Started |
| 57 | + |
| 58 | +If you're new to WebAssembly components, we recommend: |
| 59 | + |
| 60 | +1. **Start with the language you know best** - Each guide is self-contained and provides all the necessary context |
| 61 | +2. **Review the [Architecture documentation](../design/architecture.md)** - Understand how Wassette works with Wasm components |
| 62 | +3. **Check out the [Examples](https://github.com/microsoft/wassette/tree/main/examples)** - See working implementations in action |
| 63 | +4. **Read the [FAQ](../faq.md)** - Find answers to common questions |
| 64 | + |
| 65 | +## Prerequisites |
| 66 | + |
| 67 | +All guides assume basic familiarity with: |
| 68 | + |
| 69 | +- Command-line tools and terminals |
| 70 | +- Your chosen programming language |
| 71 | +- Basic WebAssembly concepts (though we explain them in each guide) |
| 72 | + |
| 73 | +## Common Concepts Across All Languages |
| 74 | + |
| 75 | +Regardless of which language you choose, you'll work with: |
| 76 | + |
| 77 | +### WIT (WebAssembly Interface Types) |
| 78 | +WIT is an Interface Definition Language (IDL) that defines how your component interacts with Wassette and other systems. All guides show you how to write WIT interfaces. |
| 79 | + |
| 80 | +Example WIT interface: |
| 81 | +```wit |
| 82 | +package local:my-tool; |
| 83 | +
|
| 84 | +world my-component { |
| 85 | + export process: func(input: string) -> result<string, string>; |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Component Model |
| 90 | +The WebAssembly Component Model provides a standard way to create portable, composable, and secure modules. Your components will follow this model regardless of the source language. |
| 91 | + |
| 92 | +### WASI (WebAssembly System Interface) |
| 93 | +WASI provides a standard interface for WebAssembly components to access system capabilities like file I/O, networking, and random number generation. Each guide explains which WASI features are available. |
| 94 | + |
| 95 | +## Testing Your Components |
| 96 | + |
| 97 | +Once you've built a component, you can test it with Wassette: |
| 98 | + |
| 99 | +```bash |
| 100 | +# Load and test your component |
| 101 | +wassette serve --sse --plugin-dir /path/to/your/component |
| 102 | + |
| 103 | +# Or load it explicitly |
| 104 | +wassette load file:///path/to/your/component.wasm |
| 105 | +``` |
| 106 | + |
| 107 | +For more details on testing, see the individual language guides. |
| 108 | + |
| 109 | +## Contributing Your Components |
| 110 | + |
| 111 | +Have you built a useful component? Consider contributing it to the [Wassette examples](https://github.com/microsoft/wassette/tree/main/examples)! See our [Contributing Guide](https://github.com/microsoft/wassette/blob/main/CONTRIBUTING.md) for details. |
| 112 | + |
| 113 | +## Next Steps |
| 114 | + |
| 115 | +Pick a language guide above and start building your first Wasm component! Each guide provides step-by-step instructions with working examples. |
| 116 | + |
| 117 | +## Additional Resources |
| 118 | + |
| 119 | +- [WebAssembly Component Model](https://component-model.bytecodealliance.org/) |
| 120 | +- [WIT Specification](https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md) |
| 121 | +- [WASI Preview 2](https://github.com/WebAssembly/WASI/blob/main/legacy/preview2/README.md) |
| 122 | +- [Model Context Protocol (MCP)](https://github.com/modelcontextprotocol/specification) |
0 commit comments