| Crates.io | waclay |
| lib.rs | waclay |
| version | 0.2.2 |
| created_at | 2025-10-01 16:29:19.778902+00 |
| updated_at | 2025-12-10 15:47:51.095594+00 |
| description | Runtime-agnostic WebAssembly Component Model implementation |
| homepage | https://github.com/HemantKArya/waclay |
| repository | https://github.com/HemantKArya/waclay |
| max_upload_size | |
| id | 1862896 |
| size | 472,669 |
A maintained fork bringing the WebAssembly Component Model to life
Features β’ Quick Start β’ Examples β’ Contributing β’ Credits
β οΈ Experimental Warning: This project is still experimental. Some features may work perfectly, others may not. It needs developer contributions to become stable.
waclay (WebAssembly Component Layer) is a runtime-agnostic implementation of the WebAssembly Component Model. This project enables you to load, link, and execute WASM components with full component model support across any WebAssembly runtime backend.
This is a maintained fork of the original wasm_component_layer project. After the original developer discontinued active maintenance, the project became difficult to compile and use with modern Rust toolchains. This fork aims to:
wit-bindgen-wcl tool for generating host bindingsThe original author's vision of a runtime-agnostic component layer combined with the wasm_runtime_layer abstraction is truly innovative. This design allows you to:
This architecture is essential for the WASM ecosystem as we wait for the Component Model to be finalized and fully supported across all runtimes.
wasm_runtime_layerwit-bindgen-wcl is a command-line tool that generates ergonomic Rust host bindings from WIT files:
Current Status: Works for simple to moderate complexity WIT files. Supports top-level functions, interfaces, records, variants, enums, options, results, and more. See the examples/ directory for supported patterns.
This workspace contains two main crates:
waclay/
βββ crates/
β βββ waclay/ # π― Core Component Layer Library
β β βββ src/ # Runtime-agnostic component model implementation
β β βββ examples/ # 10 comprehensive examples showing features
β β βββ docs/ # API documentation and guides
β β
β βββ wit-bindgen-wcl/ # π§ WIT Binding Generator (NEW!)
β βββ src/ # Code generator for host bindings
β βββ examples/ # 9 examples with generated bindings
β
βββ test-waclay.ps1 # Test suite for core library
βββ test-wit-bindgen.ps1 # Test suite for binding generator
βββ test-all.ps1 # Complete workspace tests
waclay - Core LibraryRuntime-agnostic WebAssembly Component Model implementation. Load and execute components on any WASM runtime!
wit-bindgen-wcl - Binding GeneratorGenerate type-safe Rust host bindings from WIT files. Makes working with components much more ergonomic!
# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install wasm-tools for building components
cargo install wasm-tools
cargo build
Add to your Cargo.toml:
[dependencies]
waclay = { git = "https://github.com/HemantKArya/waclay" }
# Choose your runtime backend
wasmi_runtime_layer = "0.51.0"
# OR
# wasmtime_runtime_layer = "21.0.0"
Note: Not yet published to crates.io - may be published in the future. Use git dependency for now.
Optional: Install wit-bindgen-wcl for generating bindings
If you want to generate host bindings from WIT files:
# Install the binding generator tool globally
cargo install --git https://github.com/HemantKArya/waclay wit-bindgen-wcl
# Now you can use it
wit-bindgen-wcl ./path/to/wit ./bindings.rs
git clone https://github.com/HemantKArya/waclay.git
cd waclay
# Build the workspace
cargo build --release
# Install the binding generator
cargo install --path crates/wit-bindgen-wcl
Here's a simple example of loading and calling a WASM component:
1. Define your WIT interface (guest.wit)
1. Define your WIT interface (guest.wit)
package test:guest
interface foo {
// Selects the item in position n within list x
select-nth: func(x: list<string>, n: u32) -> string
}
world guest {
export foo
}
2. Load and call the component (Rust host code)
use waclay::*;
// The bytes of the component.
const WASM: &[u8] = include_bytes!("single_component/component.wasm");
pub fn main() {
// Create a new engine for instantiating a component.
let engine = Engine::new(wasmi_runtime_layer::Engine::default());
// Create a store for managing WASM data and any custom user-defined state.
let mut store = Store::new(&engine, ());
// Parse the component bytes and load its imports and exports.
let component = Component::new(&engine, WASM).unwrap();
// Create a linker that will be used to resolve the component's imports, if any.
let linker = Linker::default();
// Create an instance of the component using the linker.
let instance = linker.instantiate(&mut store, &component).unwrap();
// Get the interface that the interface exports.
let interface = instance.exports().instance(&"test:guest/foo".try_into().unwrap()).unwrap();
// Get the function for selecting a list element.
let select_nth = interface.func("select-nth").unwrap().typed::<(Vec<String>, u32), String>().unwrap();
// Create an example list to test upon.
let example = ["a", "b", "c"].iter().map(ToString::to_string).collect::<Vec<_>>();
println!("Calling select-nth({example:?}, 1) == {}", select_nth.call(&mut store, (example.clone(), 1)).unwrap());
// Prints 'Calling select-nth(["a", "b", "c"], 1) == b'
}
That's it! You've successfully loaded and executed a WebAssembly component. π
Generate type-safe bindings from WIT files:
# Generate bindings from WIT directory
wit-bindgen-wcl ./path/to/wit ./bindings.rs
# Use in your code
cargo run --bin wit-bindgen-wcl -- ./guest.wit ./bindings.rs
Then use the generated bindings for type-safe, ergonomic API:
mod bindings;
use bindings::*; // Type-safe functions generated from WIT
// Much more ergonomic than raw Value manipulation!
wit-bindgen-wcl now supports top-level functions in WIT worlds:
world example {
// Top-level imports (host provides)
import multiply: func(a: f32, b: f32) -> f32;
// Top-level exports (guest provides)
export add: func(a: f32, b: f32) -> f32;
}
The generator creates:
linker.root_mut()instance.exports().root()This matches the wasmtime/wit-bindgen behavior and enables more flexible component designs.
βββββββββββββββββββββββββββββββββββββββββββββββ
β Your Application β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β waclay (Component Layer) β
β β’ Component Model Implementation β
β β’ Type System & Lifting/Lowering β
β β’ Resource Management β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β wasm_runtime_layer (Abstraction) β
β β’ Common Runtime Interface β
β β’ Backend Agnostic API β
ββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββ€
β Wasmi β Wasmtime β Wasmer β Browser β
β Runtime β Runtime β Runtime β (JS) β
ββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββββ
Key Benefits:
We need your help! This project is maintained and welcoming community contributions.
| Area | Priority | Description |
|---|---|---|
| π§ wit-bindgen-wcl | π΄ High | Expand binding generation for complex WIT patterns |
| π Documentation | π΄ High | API docs, tutorials, and guides |
| π§ͺ Testing | π‘ Medium | More comprehensive tests and edge cases |
| π Bug Fixes | π’ Ongoing | Report and fix issues |
| π‘ Features | π’ Ongoing | String transcoders, subtyping support |
| π¨ Examples | π’ Ongoing | More real-world use cases |
Check out existing examples and tests to understand the codebase. Don't hesitate to ask questions in issues!
# Clone your fork
git clone https://github.com/YourUsername/waclay.git
cd waclay
# Run tests to ensure everything works
.\test-all.ps1 -Fast
# Make your changes and test again
# ... your awesome contributions ...
.\test-all.ps1 -Fast
wit-bindgen-wcl functionalitywit-bindgen-wcl features#[derive(HostBindings)])Note: This project aims to bridge the gap until the Component Model is finalized by the WASI community and fully supported across all major runtimes. Community contributions are essential to keep it up-to-date.
This repository includes 20 comprehensive examples demonstrating various features:
Using the raw component API - great for learning the fundamentals:
Using the raw component API - great for learning the fundamentals:
# From workspace root
cargo run --example single_component # β
Simple component instantiation
cargo run --example string_host_guest # β
String passing between host/guest
cargo run --example func_param # β
Function parameters
cargo run --example record_response # β
Record types
cargo run --example option_result # β
Option and Result types
cargo run --example variant_return # β
Variant types
cargo run --example complex_return # β
Complex return types
cargo run --example resource # β
Resource handling
cargo run --example guest_resource # β
Guest-defined resources
cargo run --example multilevel_resource # β
Multi-level resources
Using wit-bindgen-wcl for type-safe, ergonomic code:
# From workspace root
cargo run --example bindgen-calculator # β
Calculator with logging & error handling
cargo run --example bindgen-web-scraper # β
Web scraping component
cargo run --example bindgen-single-component # β
Basic binding generation
cargo run --example bindgen-string-host-guest # β
String passing with bindings
cargo run --example bindgen-func-param # β
Function parameters with bindings
cargo run --example bindgen-record-response # β
Record types with bindings
cargo run --example bindgen-option-result # β
Option and Result with bindings
cargo run --example bindgen-variant-return # β
Variant types with bindings
cargo run --example bindgen-complex-return # β
Complex return types with bindings
# NEW: Top-level function support
cd crates/wit-bindgen-wcl/examples/toplevel-functions/host && cargo run --release
# β
Top-level function imports & exports
π‘ Tip: Examples prefixed with
bindgen-use generated bindings (more ergonomic), while others use the raw API (more flexible).
Want to build the example components yourself?
# Navigate to any component example
cd crates/wit-bindgen-wcl/examples/calculator/component
# Install nightly toolchain
rustup toolchain install nightly
rustup override set nightly
# Build the WASM module
cargo build --target wasm32-unknown-unknown --release
# Convert to component
wasm-tools component new \
target/wasm32-unknown-unknown/release/calculator.wasm \
-o component.wasm
Comprehensive test suite with cross-platform support:
# π Quick tests (recommended for development)
.\test-all.ps1 -Fast
# π Full test suite (all platforms)
.\test-all.ps1
# π― Test specific crate
.\test-waclay.ps1 # Test core library only
.\test-wit-bindgen.ps1 # Test binding generator only
# βοΈ Advanced options
.\test-waclay.ps1 -SkipAndroid -SkipLinux # Skip cross-compilation
.\test-wit-bindgen.ps1 -SkipExamples # Skip example builds
Test Coverage:
serde - Enable serialization for types and values (resources excluded as they're instance-bound)waclay = { git = "https://github.com/HemantKArya/waclay", features = ["serde"] }
π For a comprehensive feature comparison with wasmtime/wit-bindgen, see FEATURES.md
wit-bindgen-wclfuture<T>) - Requires async runtime support in corestream<T>) - Requires async runtime support in coreNote: For detailed feature comparison and workarounds, see FEATURES.md
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Huge thanks to DouglasDwyer for creating the original wasm_component_layer project. The core architecture and design are his brilliant work:
Without this foundation, this project wouldn't exist.
Maintained by HemantKArya since the original project was discontinued:
wit-bindgen-wcl toolThis project stands on the shoulders of giants:
Built with β€οΈ for the WebAssembly community
Making Component Model accessible to everyone, one runtime at a time