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§

Command
Files
A set of files loaded into memory.
Interface
The interface exported by the WebAssembly module.
Library
Metadata
Information about the Package being generated.
Module
A WebAssembly module.
Package
PackageName
The name of a package from WAPM (e.g. wasmer/wasmer-pack).
SourceFile
A file in memory.

Enums§

Abi
The Application Binary Interface used by a Module.

Constants§

GENERATOR
The generator name that will be mentioned at the top level of each generated package.
WAI_PARSER_VERSION
The versions of wai_parser this crate is compatible with.

Functions§

generate_javascript
Generate JavaScript bindings for a package.
generate_python
Generate Python bindings.