modularity
modularity
is a bare-bones library for loading and linking WebAssembly components.
It serves as a foundation for WASM-based plugin and modding systems by providing the following functionality:
- Resolving dependency graphs of WASM packages from arbitrary sources
- Instantiating WASM packages with imports from other components and the host
- Allowing the host to inspect and call package exports
Usage
The example below illustrates how to use this crate. A complete version may be found in the examples folder.
It first creates a PackageResolver
, specifying the list of packages that the application desires to load.
Then, it repeatedly calls PackageResolver::resolve
, supplying new components whenever the resolver reports that it needs them.
Once the resolver has finished building the dependency graph, it produces a PackageContextImage
. The image is subsequently applied
to the PackageContext
, where all of the components are linked and instantiated. After this, the package exports may be accessed through the context.
// Create the WASM engine and store
let engine = new;
let mut store = new;
// Create a context to hold packages
let mut ctx = default;
// Create a resolver with the list of top-level dependencies
let mut resolver = Some;
while let Some = take
modularity
relies on the wasm_component_layer
crate for creating loaded WASM modules. It is the
responsibility of the consumer to supply parsed wasm_component_layer::Component
instances from a source.