Crate wasmer_pack
source ·Expand description
A code generator that lets you treat WebAssembly modules like native dependencies.
Basic Usage
If you don’t want to use the wasmer-pack
CLI to generate bindings for your
language, you can always use this crate directly.
use wasmer_pack::{Abi, Module, Interface, Metadata, Library, Package};
// First, we need to give the package some metadata
let package_name = "username/my-package".parse()?;
let metadata = Metadata::new(package_name, "1.2.3");
// Then we'll load the libraries from disk (this example only uses one)
let module = Module::from_path("./module.wasm", Abi::None)?;
// Definitions for the functionality it exposes
let exports = Interface::from_path("./exports.wit")?;
// Functionality imported from the host
let imports = vec![
Interface::from_path("./fs.wit")?,
Interface::from_path("./logging.wit")?,
];
let libraries = vec![Library { module, exports, imports }];
let commands = Vec::new();
// finally, we've got all the information we need
let pkg = Package ::new(metadata, libraries, commands);
// Now we can generate the bindings for our language
let js = wasmer_pack::generate_javascript(&pkg)?;
// And finally, save them to disk
js.save_to_disk("./out")?;
Structs
- A set of files loaded into memory.
- The interface exported by the WebAssembly module.
- Information about the
Package
being generated. - A WebAssembly module.
- The name of a package from WAPM (e.g.
wasmer/wasmer-pack
). - A file in memory.
Enums
- The Application Binary Interface used by a
Module
.
Constants
- The generator name that will be mentioned at the top level of each generated package.
- The versions of
wai_parser
this crate is compatible with.
Functions
- Generate JavaScript bindings for a package.
- Generate Python bindings.