This project demonstrates a WebAssembly component implementation using wit-bindgen and Rust, with a Wasmtime-based host application that supports debugging.
debug-wasm/
├── wasm-component/ # WebAssembly component (Rust)
│ ├── src/lib.rs # Component implementation
│ ├── wit/world.wit # WIT interface definition
│ └── Cargo.toml # Component dependencies
├── host-app/ # Host application (Rust)
│ ├── src/main.rs # Host implementation
│ ├── wit/world.wit # WIT interface definition (copy)
│ ├── build.rs # Build script for bindings
│ └── Cargo.toml # Host dependencies
├── wasm-module/ # Legacy core wasm module (C)
│ ├── foo.c # Simple C implementation
│ └── Makefile # Build script
└── .vscode/
└── launch.json # VS Code debug configuration
The WebAssembly component exports a simple foo function:
package component:foo;
interface math {
foo: func(x: s32) -> s32;
}
world foo-world {
export math;
}The foo function takes an s32 parameter and returns x + 1.
rustup target add wasm32-wasip2
cd wasm-component
cargo build --target wasm32-wasip2cd host-app
cargo buildcd host-app
./target/debug/host-appExpected output:
foo(41) = 42
The host application enables Wasmtime debug features through environment variables:
WASMTIME_BACKTRACE_DETAILS=1: Detailed backtracesWASMTIME_LOG=debug: Debug logging
A launch configuration is provided in .vscode/launch.json for debugging the host application:
- Open the project in VS Code
- Set breakpoints in
host-app/src/main.rs - Press F5 or use "Debug Host App" configuration
- The debugger will stop at the first line (
stopOnEntry: true)
{
"name": "Debug Host App",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/host-app/target/debug/host-app",
"cwd": "${workspaceFolder}/host-app",
"env": {
"WASMTIME_BACKTRACE_DETAILS": "1",
"WASMTIME_LOG": "debug"
},
"stopOnEntry": true
}- Rust toolchain with wasm32-wasip2 target:
rustup target add wasm32-wasip2 - LLDB debugger for VS Code debugging
- VS Code with the C/C++ or CodeLLDB extension
The wasm-module/ directory contains the original C-based core WebAssembly module for comparison. It can be built with:
cd wasm-module
makeThis creates a traditional WebAssembly module that exports the same foo function but uses the core WebAssembly interface instead of the component model.