3 Enhancing portability and security with Wasm components
This chapter covers
- How Wasm components provide enhanced portability and security
- Building a Wasm component with JavaScript
- Building a custom runtime for a Wasm component with Python
- Implementing host-side functionality from a WIT file in Rust
In chapter 2, we built our first Wasm app and compiled it into a Wasm module—the thing most people think of when they hear "Wasm." But as we saw, a module on its own is stuck with only simple types like integers and floats. You can build more complex types from those, but that means both the guest and the Wasm runtime need to agree on the exact memory layout. For any real application, that's a headache.
This is where WIT comes in. It gives us a way to define higher-level types without all the manual layout work. But WIT isn't the whole story. It's part of something bigger: the Wasm Component Model. The model uses WIT as its interface definition language (IDL) and serves as a wrapper around Wasm modules. The goal is to let different Wasm applications talk to each other without all the manual memory wrangling or those fragile, implicit agreements about where structures live in linear memory.