wasmtime library

The full, wasmtime specific API.

This is the layer below package:webassembly/webassembly.dart: engines, stores, linkers, host functions and the raw value model, without the JavaScript shaped facade. Use it when you need something the WebAssembly API does not express - configuring fuel, shared memories, module serialisation, WasmMemory.grow return values, and so on.

final engine = WasmEngine();
final module = WasmModule.compile(engine, wasmBytes);
final store = WasmStore(engine);
final linker = WasmLinker(engine)
  ..defineFunction('env', 'log', WasmFuncType(parameters: [WasmValueKind.i32], results: []), (args) {
    print(args.first);
    return null;
  });
final instance = linker.instantiate(store, module);
final add = instance.export('add')! as WasmFunc;
print(add.invoke([1, 2]));

Classes

FuncHandle
A wasmtime_func_t, copied out of a value or an extern.
GlobalHandle
A wasmtime_global_t.
InstanceHandle
A wasmtime_instance_t.
Limits
A wasm_limits_t value, as used for memories and tables.
MemoryHandle
A wasmtime_memory_t.
TableHandle
A wasmtime_table_t.
WasmConfig
Configuration for a WasmEngine.
WasmEngine
A wasmtime engine: it owns the compiler and the global runtime state.
WasmExport
One entry of a module's export list.
WasmExternType
The type of an import or an export.
WasmFunc
A WebAssembly function.
WasmFuncExternType
A function import or export, with the type WebAssembly declares for it.
WasmFuncType
A WebAssembly function signature: parameters and results.
WasmGlobal
A WebAssembly global variable.
WasmGlobalExternType
A global import or export.
WasmHostTrampoline
The native trampoline behind one host function.
WasmImport
One entry of a module's import list.
WasmInstance
An instance of a WasmModule inside a WasmStore.
WasmLinker
Defines a module's imports and instantiates it.
WasmMemory
A WebAssembly linear memory.
WasmMemoryExternType
A memory import or export.
WasmModule
A compiled WebAssembly module.
WasmStore
The arena that WebAssembly objects are allocated in.
WasmTable
A WebAssembly table.
WasmTableExternType
A table import or export.

Enums

WasmExternKind
What kind of thing an import or an export is.
WasmOptLevel
How hard cranelift tries to optimise.
WasmStrategy
The code generator wasmtime compiles with.
WasmValueKind
The kinds of value that can cross the WebAssembly boundary.

Extensions

WasmEngineCompilation on WasmEngine
Compilation helpers on the engine, kept here to avoid a circular import.

Functions

dartToExtern(Arena arena, Object value) → Pointer<wasmtime_extern_t>
Writes value into a fresh wasmtime_extern_t allocated in arena.
externToDart(WasmStore store, Pointer<wasmtime_extern_t> item) → Object?
Turns a filled wasmtime_extern_t into the matching wrapper and consumes it.
toDartValue(WasmStore store, WasmValueKind kind, Object? value) → Object?
Converts a value read from the C API into the object layer's form.
toNativeValue(WasmValueKind kind, Object? value) → Object?
Converts an object layer value into what the value layer expects.
trapCodeName(int code) → String
The human readable name of a WASMTIME_TRAP_CODE_* value.

Typedefs

WasmHostFunction = Object? Function(List<Object?> arguments)
A Dart function that WebAssembly imports.

Exceptions / Errors

WasmtimeException
A failure reported by wasmtime itself: compiling, linking, growing a memory, setting fuel that is not configured, and so on.
WasmTrapException
A trap: WebAssembly execution was aborted (unreachable, out of bounds memory access, stack overflow, an uncaught host exception, ...).