Crates.io | wasmer-asml-fork |
lib.rs | wasmer-asml-fork |
version | 2.0.0 |
source | src |
created_at | 2021-02-06 02:48:15.689721 |
updated_at | 2021-10-29 03:45:35.981965 |
description | High-performant WebAssembly runtime |
homepage | |
repository | https://github.com/wasmerio/wasmer |
max_upload_size | |
id | 351384 |
size | 249,818 |
wasmer
Wasmer
is the most popular
WebAssembly runtime for Rust (...and also
the fastest). 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.
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 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(&module, &import_object)?;
let add_one = instance.exports.get_function("add_one")?;
let result = add_one.call(&[Value::I32(42)])?;
assert_eq!(result[0], Value::I32(43));
Ok(())
}
Wasmer is not only fast, but also designed to be highly customizable:
dlopen
implementation? This is for you!serialized
Module (via Module::deserialize()
).Module::serialize()
).Wasmer has the following configuration flags:
wat
(enabled by default): It allows to read WebAssembly files in their text format.
This feature is normally used only in development environmentssinglepass
: it will use wasmer-compiler-singlepass
as the default
compiler (ideal for blockchains).cranelift
: it will use wasmer-compiler-cranelift
as the default
compiler (ideal for development).llvm
: it will use wasmer-compiler-llvm
as the default
compiler (ideal for production).Wasmer ships by default with the cranelift
compiler as its great for development proposes.
However, we strongly encourage to use the llvm
backend in production as it performs
about 50% faster, achieving near-native speeds.
Note: if you want to use multiple compilers at the same time, it's also possible! You will need to import them directly via each of the compiler crates.
Made with ❤️ by the Wasmer team, for the community