Wasmer Examples
This directory contains a collection of examples. This isn't an exhaustive collection though, if one example is missing, please ask, we will be happy to fulfill your needs!
Examples
The examples are written in a difficulty/discovery order. Concepts that are explained in an example is not necessarily re-explained in a next example.
Engines
-
JIT engine, explains what an engine is, what the JIT engine is, and how to set it up. The example completes itself with the compilation of the Wasm module, its instantiation, and finally, by calling an exported function.
Keywords: JIT, engine, in-memory, executable code.
Execute the example
$ cargo run --example engine-jit --release --features "cranelift" -
Native engine, explains what a native engine is, and how to set it up. The example completes itself with the compilation of the Wasm module, its instantiation, and finally, by calling an exported function.
Keywords: native, engine, shared library, dynamic library, executable code.
Execute the example
$ cargo run --example engine-native --release --features "cranelift" -
Headless engines, explains what a headless engine is, what problem it does solve, and what are the benefits of it. The example completes itself with the instantiation of a pre-compiled Wasm module, and finally, by calling an exported function.
Keywords: native, engine, constrained environment, ahead-of-time compilation, cross-compilation, executable code, serialization.
Execute the example
$ cargo run --example engine-headless --release --features "cranelift" -
Cross-compilation, illustrates the power of the abstraction over the engines and the compilers, such as it is possible to cross-compile a Wasm module for a custom target.
Keywords: engine, compiler, cross-compilation.
Execute the example
$ cargo run --example cross-compilation --release --features "cranelift"
Compilers
-
Singlepass Compiler, explains how to use the Singlepass compiler.
Keywords: engine, compiler, singlepass.
Execute the example
$ cargo run --example compiler-singlepass --release --features "singlepass" -
Cranelift Compiler, explains how to use the Cranelift compiler.
Keywords: engine, compiler, cranelift.
Execute the example
$ cargo run --example compiler-cranelift --release --features "cranelift" -
LLVM Compiler, explains how to use the LLVM compiler.
Keywords: engine, compiler, llvm.
Execute the example
$ cargo run --example compiler-llvm --release --features "llvm"
Exports
-
Exported function, explains how to get and how to call an exported function. They come in 2 flavors: dynamic, and “static”/native. The pros and cons are discussed briefly.
Keywords: export, function, dynamic, static, native.
Execute the example
$ cargo run --example exported-function --release --features "cranelift"
Integrations
-
WASI integration, explains how to get and how to call an exported function. They come in 2 flavors: dynamic, and “static”/native. The pros and cons are discussed briefly.
Keywords: export, function, dynamic, static, native.
Execute the example
$ cargo run --example wasi --release --features "cranelift,wasi"