https://github.com/pulseengine/wasm-component-examples
WebAssembly Component Model examples using rules_wasm_component with Bazel (C, C++, Rust, WASI-NN)
https://github.com/pulseengine/wasm-component-examples
Last synced: 3 months ago
JSON representation
WebAssembly Component Model examples using rules_wasm_component with Bazel (C, C++, Rust, WASI-NN)
- Host: GitHub
- URL: https://github.com/pulseengine/wasm-component-examples
- Owner: pulseengine
- License: apache-2.0
- Created: 2025-12-31T10:57:33.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-02-08T18:47:15.000Z (4 months ago)
- Last Synced: 2026-02-09T00:28:33.180Z (4 months ago)
- Language: Rust
- Size: 512 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wasm-component-examples
Working examples for WebAssembly Component Model



Examples demonstrating the [WebAssembly Component Model](https://component-model.bytecodealliance.org/) using [rules_wasm_component](https://github.com/pulseengine/rules_wasm_component) with Bazel.
> [!NOTE]
> Part of the PulseEngine toolchain. Demonstrates patterns used across the PulseEngine toolchain.
## Examples
| Example | Language | Type | Description |
|---------|----------|------|-------------|
| `//c:hello_c` | C | Library | Exports `greeter` interface |
| `//cpp:hello_cpp` | C++ | Library | Exports `greeter` interface |
| `//go:hello_go` | Go | CLI | Hello world with TinyGo |
| `//rust:hello_rust` | Rust | CLI | Hello world CLI component |
| `//rust:calculator` | Rust | CLI | Arithmetic calculator |
| `//rust:datetime` | Rust | CLI | Shows current date/time |
| `//rust:yolo_inference` | Rust | CLI + WASI-NN | YOLO object detection |
## Prerequisites
- [Bazel](https://bazel.build/) 7.0+
- [Wasmtime](https://wasmtime.dev/) (for running components)
- For YOLO: Wasmtime compiled with ONNX backend support
## Build
```bash
# Build all examples
bazel build //...
# Build specific example
bazel build //rust:hello_rust
bazel build //rust:yolo_inference_release
```
## Run
### Rust CLI Components
```bash
# Hello world
wasmtime bazel-bin/rust/hello_rust.runfiles/_main/rust/hello_rust_host.wasm
# Calculator
wasmtime bazel-bin/rust/calculator.runfiles/_main/rust/calculator_host.wasm 8 + 8
# DateTime
wasmtime bazel-bin/rust/datetime.runfiles/_main/rust/datetime_host.wasm
```
### YOLO Object Detection
Requires ONNX model (see `models/README.md`):
```bash
# Download model
curl -L -o models/yolov8n.onnx \
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.onnx
mkdir -p models/yolov8n && ln -sf ../yolov8n.onnx models/yolov8n/model.onnx
# Run detection
wasmtime run --dir . -S cli -S nn -S nn-graph=onnx::./models/yolov8n \
bazel-out/darwin_arm64-fastbuild-ST-*/bin/rust/yolo_inference_wasm_lib_release_wasm_base.wasm \
./bus.jpg
```
## Project Structure
```
.
├── c/ # C hello world component
├── cpp/ # C++ hello world component
├── rust/ # Rust components
│ ├── src/
│ │ ├── main.rs # hello_rust
│ │ ├── calculator.rs # calculator
│ │ ├── datetime.rs # datetime
│ │ └── yolo_inference.rs # YOLO detection logic
│ └── wit/yolo.wit
├── models/ # ONNX models (download separately)
├── MODULE.bazel
└── BUILD.bazel
```
## Component Types
### Library Components (C/C++)
Export custom interfaces that can be composed with other components:
```wit
interface greeter {
greet: func() -> string;
}
world hello-c {
export greeter;
}
```
### CLI Components (Rust)
Export `wasi:cli/run` for direct execution with Wasmtime.
## CI/CD
- **CI** (`ci.yml`): Builds all components on Linux and macOS, runs Rust CLI tests
- **Release** (`release.yml`): Creates signed releases with provenance attestation
## License
Apache-2.0
---
Part of PulseEngine — formally verified WebAssembly toolchain for safety-critical systems