erlang-wasmtime

Wasmtime bindings for Erlang (also findable as wasmtime-erlang). WebAssembly modules run natively through Wasmtime's Cranelift compiler, and a module can call Erlang functions when it needs to, the way erlang-python lets Python call Erlang.

{ok, Mod} = wasmtime:compile({wat, ~"""
(module
(import "env" "log" (func $log (param i32) (result i32)))
(func (export "run") (param i32) (result i32)
local.get 0 call $log))
"""}),
{ok, Inst} = wasmtime:instantiate(Mod, #{
imports => #{{~"env", ~"log"} => fun(_Ctx, [N]) -> logger:info("got ~p", [N]), {ok, [N * 2]} end}}),
{ok, [84]} = wasmtime:call(Inst, ~"run", [42]).

Nothing raises for guest failures. Compile, link, trap, WASI and host errors all come back as {error, #{class => ..., kind => ..., message => ...}}.

What you get

Install

{deps, [{erlang_wasmtime, "0.1.1"}]}.

The first rebar3 compile downloads the pinned Wasmtime C API release for your platform (about 15 MB, checksum verified) and builds the NIF. You need a C compiler and curl; a platform without a prebuilt archive builds Wasmtime from source with git, cmake and Rust. See docs/building.md for offline builds, runtime-only builds and supported platforms.

Requires OTP 27 or later.

Documentation

License

Apache-2.0