This repository contains the Wasmtime-based host runtime and WebAssembly guest components for the WASI-USB ecosystem. It demonstrates capability-based USB access from Wasm, with a real-time UVC webcam capture demo as the primary example.
Original research and implementation by IDLab Discover.
wit/: WIT interface definitions — an exact mirror ofwasi-usb/wit/(component:usb@0.2.1). Extended withworld.witthat defineshost,cguest, andwebcam-guestworlds. The canonical source of truth iswasi-usb/wit/; update there first, then mirror here.usb-wasm/: Host-side implementation of the WASI-USB WIT interfaces. Bridges libusb to the Wasmtime async runtime (host_impl.rs,usb_backend.rs).wasmtime-usb/: Wasmtime-based CLI runner that incorporates theusb-wasmhost implementation.command-components/: Guest components implementing USB logic —lsusb,webcam,streams-test,enumerate-devices-rust.usb-wasm-bindings/: Pre-generated Rust bindings for thecguestworld (used by benchmark guest components). The webcam guest uses inlinewit_bindgen::generate!instead.
- Rust (latest stable)
- wasm-tools
- just
- wit-bindgen-cli v0.42.1 (only needed to regenerate
usb-wasm-bindings/src/cguest.rs)
We use just as the primary build system. Run just --list to see all available recipes.
cargo build # builds the wasmtime-usb host binaryjust build-webcam # compiles webcam guest to wasm32-wasip2 component
just webcam # runs with sudo; streams MJPEG frames from any UVC cameraThe webcam guest handles the full UVC probe/commit negotiation, alternate-setting switching, and MJPEG reassembly from isochronous packets. The host provides only raw USB transfers.
just lsusb # list USB devices
just enumerate-devices-rust # device enumeration demo
just streams-test # USB 3.0 Bulk Streams validation (SanDisk USB 3.0 stick)Note
sudo is required for direct USB access on Linux/macOS unless udev rules grant permission to the current user.
This work has been partially supported by the ELASTIC project, which received funding from the Smart Networks and Services Joint Undertaking (SNS JU) under the European Union's Horizon Europe research and innovation programme under Grant Agreement No 101139067. Views and opinions expressed are those of the author(s) only.