1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//! 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.
//!
//! ```rust,no_run
//! 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);
//!
//! // we setup the options that are passed to the generator
//! let options = wasmer_pack::BindingsOptions::default();
//!
//! // Now we can generate the bindings for our language
//! let js = wasmer_pack::generate_javascript(&pkg, &options)?;
//!
//! // And finally, save them to disk
//! js.save_to_disk("./out")?;
//! # Ok::<(), anyhow::Error>(())
//! ```
#[macro_use]
#[cfg(test)]
extern crate pretty_assertions;
mod files;
mod js;
mod pirita;
mod py;
mod types;
mod versions;
pub use crate::{
files::{Files, SourceFile},
js::generate_javascript,
py::generate_python,
types::BindingsOptions,
types::{Abi, Command, Interface, Library, Metadata, Module, Package, PackageName},
versions::WAI_PARSER_VERSION,
};
/// The generator name that will be mentioned at the top level of each generated
/// package.
pub const GENERATOR: &str = concat!(env!("CARGO_PKG_NAME"), " v", env!("CARGO_PKG_VERSION"));