2 releases
| 0.2.1 | Oct 5, 2025 |
|---|---|
| 0.2.0 | Oct 1, 2025 |
#1045 in WebAssembly
227 downloads per month
365KB
7K
SLoC
π waclay
WebAssembly Component Layer - Runtime Agnostic
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.
π About This Project
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.
π― Why This Fork?
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:
- β Keep it compiling - Updated to work with latest Rust and dependencies (50+ commits of fixes and improvements)
- β
Add new features - Including the new
wit-bindgen-wcltool for generating host bindings - β Maintain usability - Making it a practical tool for plugin development and WASM-based applications
- β Stay runtime agnostic - Preserving the brilliant design that works with Wasmi, Wasmtime, and other backends
- β Build community - Welcoming contributions to help maintain and improve the project
π‘ The Brilliant Design
The 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:
- Switch between different WASM runtimes (Wasmi, Wasmtime, etc.) without changing your code
- Use the same Component Model API regardless of the underlying execution engine
- Build portable WASM applications that work across multiple platforms and backends
This architecture is essential for the WASM ecosystem as we wait for the Component Model to be finalized and fully supported across all runtimes.
β¨ Features
Core Capabilities
- π§ Component Model Support - Full implementation of WebAssembly Component Model
- π Runtime Agnostic - Works with Wasmi, Wasmtime, and any backend via
wasm_runtime_layer - π Type System - Complete support for WIT types: records, variants, enums, resources, etc.
- π Zero Unsafe Code - 100% safe Rust implementation
- π¦ Resource Management - Proper handling of owned and borrowed resources with destructors
- π Dynamic Loading - Runtime inspection and generation of component interface types
- β‘ Optimized Lists - Specialized list types for faster lifting/lowering operations
NEW: wit-bindgen-wcl
wit-bindgen-wcl is a command-line tool that generates ergonomic Rust host bindings from WIT files:
- β¨ Type-Safe Bindings - Generates strongly-typed Rust code from WIT definitions
- π― Easy Integration - Simple workflow from WIT β Rust bindings β Host application
- π§ Active Development - Basic features working for simple use cases (see examples)
- π€ Community Needed - Heavy development in progress, contributions welcome!
Current Status: Works for simple to moderate complexity WIT files. See the examples/ directory for supported patterns.
ποΈ Workspace Structure
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
π¦ Crates
waclay - Core Library
Runtime-agnostic WebAssembly Component Model implementation. Load and execute components on any WASM runtime!
- Version: 0.1.3
- License: Apache-2.0
- Repository: https://github.com/HemantKArya/waclay
wit-bindgen-wcl - Binding Generator
Generate type-safe Rust host bindings from WIT files. Makes working with components much more ergonomic!
- Status: Basic features working, contributions welcome
- Use Cases: Simple to moderate complexity WIT files (check examples)
- Community: Contributors needed to expand capabilities
π Quick Start
Prerequisites
# 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
Installation
cargo build
Installation
Option 1: Use in Your Project (Recommended)
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
Option 2: Build from Source
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
Basic Usage Example
Basic Usage Example
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. π
Using wit-bindgen-wcl for Better Ergonomics
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!
π― How It Works
The Runtime Agnostic Architecture
βββββββββββββββββββββββββββββββββββββββββββββββ
β 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:
- Write once, run anywhere - Your code works with any runtime
- Easy runtime switching - Change one line to switch backends
- Future-proof - As new runtimes emerge, they just work
- Testability - Test with lightweight runtime, deploy with optimized one
π€ Contributing
We need your help! This project is maintained and welcoming community contributions.
Why Contribute?
- π Shape the Future - Help build critical WebAssembly infrastructure
- π Learn WASM - Deep dive into Component Model internals
- π― Real Impact - Used in production for plugin systems and WASM applications
- π€ Welcoming Community - All skill levels welcome, we'll help you get started
What We Need
| 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 |
Getting Started
- Fork the repository
- Pick an issue or create a new one
- Make your changes with tests
- Submit a PR with a clear description
Check out existing examples and tests to understand the codebase. Don't hesitate to ask questions in issues!
Development Setup
# 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
πΊοΈ Roadmap
Current Focus (v0.1.x)
- Maintain compatibility with latest Rust
- Basic
wit-bindgen-wclfunctionality - Comprehensive documentation
- More
wit-bindgen-wclfeatures - String transcoder support
- Subtyping support
Future (v0.2.x+)
- Publish to crates.io
- Host binding macro (
#[derive(HostBindings)]) - Performance optimizations
- More runtime backend support
- WASI Preview 2 integration examples
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.
π Examples
This repository includes 19 comprehensive examples demonstrating various features:
πΉ Core Library Examples (10 examples)
Using the raw component API - great for learning the fundamentals:
πΉ Core Library Examples (10 examples)
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
πΈ Generated Bindings Examples (9 examples)
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
π‘ Tip: Examples prefixed with
bindgen-use generated bindings (more ergonomic), while others use the raw API (more flexible).
Building Your Own Components
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
π§ͺ Testing
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:
- β Unit tests and integration tests
- β All 19 examples build and run
- β Cross-platform compatibility (Windows, Linux, Android)
- β Multiple runtime backends
βοΈ Optional Features
serde- Enable serialization for types and values (resources excluded as they're instance-bound)
waclay = { git = "https://github.com/HemantKArya/waclay", features = ["serde"] }
π Supported Capabilities
β Fully Supported
- β Component parsing and instantiation
- β All WIT types (records, variants, enums, options, results, etc.)
- β Specialized list types for performance
- β Structural type equality
- β Guest resources
- β Host resources with destructors
- β Runtime type inspection
- β Multiple runtime backends
π§ In Progress
- π§
wit-bindgen-wcl- Basic features working, expanding coverage - π§ Comprehensive testing suite
- π§ Documentation and tutorials
π Planned
- π String transcoders
- π Host binding macros
- π Subtyping support
- π Performance benchmarks
π License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
π Credits
Original Author
Huge thanks to DouglasDwyer for creating the original wasm_component_layer project. The core architecture and design are his brilliant work:
- π‘ Visionary Design - The runtime-agnostic component layer concept
- ποΈ Solid Foundation - Clean, well-structured codebase
- π§ wasm_runtime_layer - The abstraction that makes it all possible
Without this foundation, this project wouldn't exist.
This Fork
Maintained by HemantKArya since the original project was discontinued:
- π Trying to keep it compiling with modern Rust
- β¨ New
wit-bindgen-wcltool - π Improved documentation
- π€ Community building
Built With
This project stands on the shoulders of giants:
- wasmtime - Component Model implementation reference
- wit-parser - WIT parsing and validation
- wasm_runtime_layer - Runtime abstraction
- All the runtime backends: Wasmi, Wasmtime, and others
π Get in Touch
- π Found a bug? Open an issue
- π‘ Have an idea? Start a discussion
- π€ Want to contribute? Check our Contributing section
- β Like the project? Give us a star on GitHub!
Built with β€οΈ for the WebAssembly community
Making Component Model accessible to everyone, one runtime at a time
Dependencies
~9β13MB
~256K SLoC