2 releases

4.3.6-hc.1 Aug 28, 2024
4.3.6-hc.0 Aug 27, 2024

#91 in WebAssembly

Download history 358/week @ 2024-08-24 90/week @ 2024-08-31 72/week @ 2024-09-07 190/week @ 2024-09-14 464/week @ 2024-09-21 171/week @ 2024-09-28 226/week @ 2024-10-05 210/week @ 2024-10-12 294/week @ 2024-10-19 563/week @ 2024-10-26 274/week @ 2024-11-02 318/week @ 2024-11-09

1,461 downloads per month
Used in 2 crates

MIT license

9MB
224K SLoC

C 145K SLoC // 0.1% comments Rust 32K SLoC // 0.0% comments C++ 19K SLoC // 0.2% comments Python 10K SLoC // 0.1% comments WebAssembly 9K SLoC // 0.0% comments Shell 4K SLoC // 0.1% comments TypeScript 2K SLoC // 0.1% comments TSX 1K SLoC // 0.0% comments GNU Style Assembly 810 SLoC // 0.2% comments Go 721 SLoC // 0.2% comments Scons 209 SLoC // 0.3% comments Batch 101 SLoC Assembly 100 SLoC // 0.2% comments C# 72 SLoC // 0.3% comments JavaScript 47 SLoC // 0.2% comments Bitbake 17 SLoC // 0.3% comments

Contains (ELF exe/lib, 14KB) binarydump

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), AOT (Ahead Of Time) compilation, an experimental interpreter 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):

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

fn main() -> anyhow::Result<()> {
    let module_wat = r#"
    (module
    (type $t0 (func (param i32) (result i32)))
    (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
        get_local $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:

  • Pluggable compilers — A compiler is used by the engine to transform WebAssembly into executable code:

  • Pluggable interpreters (experimental) - wamr, a feature provided by the wasmer crate, provides binding to the interpreter provided by WAMR. More informations about this experimental backend can be found in the dedicated documentation.

  • Headless mode — Once a WebAssembly module has been compiled, it is possible to serialize it in a file for example, and later execute it with Wasmer with headless mode turned on. Headless Wasmer has no compiler, which makes it more portable and faster to load. It's ideal for constrainted environments.

  • Cross-compilation — Most compilers support cross-compilation. It means it possible to pre-compile a WebAssembly module targetting a different architecture or platform and serialize it, to then run it on the targetted architecture and platform later.

  • Run Wasmer in a JavaScript environment — With the js Cargo feature, it is possible to compile a Rust program using Wasmer to WebAssembly. In this context, the resulting WebAssembly module will expect to run in a JavaScript environment, like a browser, Node.js, Deno and so on. In this specific scenario, there is no engines or compilers available, it's the one available in the JavaScript environment that will be used.

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

Dependencies

~4–18MB
~263K SLoC