Skip to content

Latest commit

 

History

History
 
 

examples

Examples

This directory contains a collection of examples. This isn't an exhaustive collection though, if one is missing, please ask, we will be happy to fulfill your needs!

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.

Basics

  1. Instantiating a module, explains the basics of using Wasmer and how to create an instance out of a WebAssembly module.

    Keywords: instance, module.

    Execute the example
    $ python examples/instance.py

Engines

  1. Universal engine, explains what an engine is, what the Universal 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: universal, engine, in-memory, executable code.

    Execute the example
    $ python examples/engine_universal.py
  2. Dylib engine, explains what a Dylib 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: dylib, engine, shared library, dynamic library, executable code.

    Execute the example
    $ python examples/engine_dylib.py
  3. 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: dylib, engine, constrained environment, ahead-of-time compilation, cross-compilation, executable code, serialization.

    Execute the example
    $ python examples/engine_headless.py
  4. 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
    $ python examples/engine_cross_compilation.py

Compilers

  1. Singlepass compiler, explains how to use the wasmer_compiler_singlepass compiler.

    Keywords: compiler, singlepass.

    Execute the example
    $ python examples/compiler_singlepass.py
  2. Cranelift compiler, explains how to use the wasmer-compiler-cranelift compiler.

    Keywords: compiler, cranelift.

    Execute the example
    $ python examples/compiler_cranelift.py
  3. LLVM compiler, explains how to use the wasmer-compiler-llvm compiler.

    Keywords: compiler, llvm.

    Execute the example
    $ python examples/compiler_llvm.py

Exports

  1. Exported function, explains how to get and how to call an exported function.

    Keywords: export, function.

    Execute the example
    $ python examples/exports_function.py
  2. Exported memory, explains how to read from and write into an exported memory.

    Keywords: export, function.

    Execute the example
    $ python examples/exports_memory.py
  3. Exported global, explains how to work with exported globals: get/set their value, have information about their type.

    Keywords: export, global.

    Execute the example
    $ python examples/exports_global.py

Imports

  1. Imported function, aka host function, explains how to use a Python function inside a WebAssembly module.

    Keywords: import, function.

    Execute the example
    $ python examples/imports_function.py
  2. Early exit, explains how to early exit from a host function, and how to catch the error later.

    Keywords: import, function, error.

    Execute the example
    $ python examples/imports_function_early_exit.py

Integrations

  1. WASI, explains how to use the WebAssembly System Interface (WASI).

    Keywords: wasi, system, interface

    Execute the example
    $ python examples/wasi.py