Create WebAssembly Components with Rust’s cargo component
In this Shortcut, I am going to show you how to use a plug-in to Rust’s cargo
tool to generate and build WebAssembly components. In the “Create WebAssembly Components with wasm-tools” Shortcut, I used wasm-tools
and a .wat
implementation to do this. In doing so, I demonstrated that there are no intrinsic dependencies on a language such as Rust to create these components.
If you have not yet read that Shortcut, you should do so in order to better understand what I am highlighting in this one. That was a general overview of components, whereas this is a more specific way of creating and using them. Go ahead; I’ll wait.
cargo component
is intended as a tool to make the interactions between Rust and WebAssembly components even more idiomatic from a Rust perspective. It will generate the project scaffolding, the necessary bindings to bridge .wit
types and Rust, and support for building components. It relies on the same underlying principles I introduced in the Shortcut mentioned above, but aligns it with the Rust ecosystem more tightly.
In the GitHub repository for this Shortcut, you should enter the directory 23-Wasm-Components-Rust
. In it, you will find a readme.md
file describing the installation instructions for the tools so you can follow along below. You will also notice the same example-host
directory that we have looked at previously; it contains an application ...
Get Create WebAssembly Components with Rust's cargo component now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.