0.3.0
Added
-
Memory can be imported, thus making the distinction between owned and borrowed memory (#119 by @koponen-styra).
The main new methods are
Imports.AppendMemory
, andNewMemory
to create a new memory with bounds (in pages).The
Imports.Append
method is now deprecated in favor ofImports.AppendFunction
.// Compile a WebAssembly module module, _ := wasm.Compile(wasmBytes) // Create a new memory (that's new!) memory, _ := wasm.NewMemory(/* min page */ 1, /* max page */ 2) // Create an import object imports := wasm.NewImports().Namespace("env").AppendMemory("memory", memory) importObject := wasm.NewImportObject() _ = importObject.Extend(*imports) instance, _ := module.InstantiateWithImportObject(importObject) defer instance.Close() // Now we can read or write the memory with `memory.Data()` as usual
-
Add Bazel files to build the project with Bazel (#108 by @joesonw)
-
Support multiple WASI version with
WasiGetVersion
,NewDefaultWasiImportObjectForVersion
,NewWasiImportObjectForVersion
andWasiVersion
(#92 by @Hywan).Supported version are:
Latest
,Snapshot0
,Snapshot1
,Unknown
(in case of error).
// Compile a WebAssembly module module, _ = wasm.Compile(wasmBytes) // Read the WASI version required for this module wasiVersion = wasm.WasiGetVersion(module) // Create an import object importObject := wasm.NewDefaultWasiImportObjectForVersion(wasiVersion) // Extend the import object with the imports imports, _ := wasm.NewImports().Namespace("env").AppendFunction("sum", sum, C.sum) _ = importObject.Extend(*imports) // Instantiate the module with the import object instante, _ := module.InstantiateWithImportObject(importObject)
-
InstanceContext
supports user data with any reference types or types that include any reference types or other Go pointers (#85 and #94 by @AdamSLevy)type logMessageContext struct { message string slice []string // that wasn't possible before ptr *string // that wasn't possible before } str := "test" contextData = logMessageContext { message: "first", slice: []string{str, str}, ptr: &str, } instance.SetContextData(&contextData)
-
WASI is now supported (#72 by @MarkMcCaskey)
// Compile a WebAssembly module module, _ = wasm.Compile(wasmBytes) // Declare imports as usual imports, _ := wasm.NewImports().Namespace("env").AppendFunction("sum", sum, C.sum) // Create an import object importObject := wasm.NewDefaultWasiImportObject() // Extend the import object with the imports _ = importObject.Extend(*imports) // Instantiate the module with the import object instance, _ = wasm.InstantiateWithImportObject(importObject) defer instance.Close() // Run the module instance.Exports["_start"]()
-
Instance
supports optional memory, i.e. a WebAssembly module that does not have an exported memory, and provides a newHasMemory
method (#63 by @Hywan)
Changed
- Remove unnecessary heap allocations and calls to C (#118 by @koponen-styra)
- Update the
cli
package version to v2 (#110 by @d0iasm) - Migrate from CircleCI to Github Actions (#99 and #103 by @Hywan)
- Explain how this package works (#97 by [@Hywan])
- Make tests more portable by changing
int64_t
tolong long
in cgo (#67 by @ethanfrey) - Update build instructions (#66 by @ethanfrey)
- Update Wasmer to 0.6.0 to 0.14.0 (#57, #64, #73, #80, #89, #107, #111 and #120 by @Hywan)