wasmer Build Status Join Wasmer Slack MIT License crates.io

Wasmer is the most popular WebAssembly runtime for Rust. It supports JIT (Just In Time) and AOT (Ahead Of Time) compilation as well as pluggable compilers suited to your needs.

It's designed to be safe and secure, and runnable in any kind of environment.

Usage

Here is a small example of using Wasmer to run a WebAssembly module written with its WAT format (textual format):

```rust use wasmer::{Store, Module, Instance, Value, imports};

fn main() -> anyhow::Result<()> { let modulewat = r#" (module (type $t0 (func (param i32) (result i32))) (func $addone (export "addone") (type $t0) (param $p0 i32) (result i32) getlocal $p0 i32.const 1 i32.add)) "#;

let mut store = Store::default();
let module = Module::new(&store, &module_wat)?;
// The module doesn't import anything, so we create an empty import object.
let import_object = imports! {};
let instance = Instance::new(&mut store, &module, &import_object)?;

let add_one = instance.exports.get_function("add_one")?;
let result = add_one.call(&mut store, &[Value::I32(42)])?;
assert_eq!(result[0], Value::I32(43));

Ok(())

} ```

Discover the full collection of examples.

Features

Wasmer is not only fast, but also designed to be highly customizable:

Wasmer ships by default with the Cranelift compiler as its great for development purposes. However, we strongly encourage to use the LLVM compiler in production as it performs about 50% faster, achieving near-native speeds.

Note: if one wants to use multiple compilers at the same time, it's also possible! One will need to import them directly via each of the compiler crates.

Read the documentation to learn more.


Made with ❤️ by the Wasmer team, for the community