| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
| Example | Language | Type | Description |
|---|---|---|---|
| //c:hello_c | C | Library | Exports greeter interface |
| //cpp:hello_cpp | C++ | Library | Exports greeter interface |
| //cpp:stats | C++ | Library | Descriptive statistics (mean, median, percentile) |
| //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 |
| //rust_p3:text_processor | Rust | Library (P3) | Async text analysis and transformation |
| //rust_p3:concurrent_tasks | Rust | Library (P3) | Async math computations (fibonacci, prime, collatz) |
| //rust_p3:p3_cli | Rust | CLI (composed) | Runner composed with text_processor + concurrent_tasks via wac |
# Build all examples
bazel build //...
# Build specific example
bazel build //rust:hello_rust
bazel build //rust:yolo_inference_release# 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.wasmRequires 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. ├── 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 ├── rust_p3/ # Rust P3 async components + composed CLI │ ├── src/ │ │ ├── text_processor.rs # text analysis & transformation │ │ ├── concurrent.rs # math computations (fib, prime, collatz) │ │ └── cli_runner.rs # CLI runner (imports P3 interfaces) │ └── wit/ │ ├── text_processor.wit │ ├── concurrent.wit │ └── cli_runner.wit # imports P3 + WASI CLI interfaces ├── models/ # ONNX models (download separately) ├── MODULE.bazel └── BUILD.bazel
Export custom interfaces that can be composed with other components:
interface greeter {
greet: func() -> string;
}
world hello-c {
export greeter;
}Export wasi:cli/run for direct execution with Wasmtime.
The rust_p3/ directory demonstrates WASI Preview 3 async components. Setting wasi_version = "p3" on a rust_wasm_component_bindgen target passes --async to wit-bindgen, making all exported trait methods async fn. This enables cooperative concurrency within the Component Model.
Exports two async interfaces:
Exports async mathematical functions designed for concurrent dispatch:
A CLI runner component composed with the P3 libraries via wac_plug. Demonstrates the full component model workflow: build library components, build a CLI runner that imports their interfaces, compose with wac into a single runnable binary.
# Build the composed CLI
bazel build //rust_p3:p3_cli
# Run (requires wasmtime with component-model-async support)
wasmtime run -W component-model-async=y bazel-bin/rust_p3/p3_cli.wasm analyze "the quick brown fox"
wasmtime run -W component-model-async=y bazel-bin/rust_p3/p3_cli.wasm fibonacci 10
wasmtime run -W component-model-async=y bazel-bin/rust_p3/p3_cli.wasm transform uppercase "hello world"
wasmtime run -W component-model-async=y bazel-bin/rust_p3/p3_cli.wasm batch 5 10 15See rust_p3/src/text_processor.rs and rust_p3/src/concurrent.rs for the async implementation pattern using #[cfg(target_arch)] gates.
Apache-2.0
Part of PulseEngine — formally verified WebAssembly toolchain for safety-critical systems
| Back | FazBrowse Home | New Git URL |