Skip to content

WebAssembly Component Model examples using rules_wasm_component with Bazel (C, C++, Rust, WASI-NN)

License

Notifications You must be signed in to change notification settings

pulseengine/wasm-component-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wasm-component-examples

Working examples for WebAssembly Component Model

 

Bazel WebAssembly License: Apache-2.0

 

Examples demonstrating the WebAssembly Component Model using 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 7.0+
  • Wasmtime (for running components)
  • For YOLO: Wasmtime compiled with ONNX backend support

Build

# Build all examples
bazel build //...

# Build specific example
bazel build //rust:hello_rust
bazel build //rust:yolo_inference_release

Run

Rust CLI Components

# 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):

# 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:

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

About

WebAssembly Component Model examples using rules_wasm_component with Bazel (C, C++, Rust, WASI-NN)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •