Releases: wasmerio/wasmer-go
v1.0.4
v1.0.3
Added
- #213 Add the
CompilerKind
,EngineKind
,IsCompilerAvailable
andIsEngineAvailable
symbols. - #206 Use parameterized tests to check all available configurations.
- #204 Add
Config.UseSinglepassCompiler
. - #193, #190 and #211 Add the
custom_wasmer_runtime
build tag. - #192 Add missing documentation.
Changed
(nothing)
Fixed
v1.0.2
v1.0.1
v1.0.0
v1.0.0-beta2
Update to Wasmer 1.0.0
v1.0.0-beta1
Changed
-
The whole API changed to better match Wasmer and Wasm C API
// Create an Engine engine := wasmer.NewEngine() // Create a Store store := wasmer.NewStore(engine) fmt.Println("Compiling module...") module, err := wasmer.NewModule(store, wasmBytes) if err != nil { fmt.Println("Failed to compile module:", err) } // Create an empty import object. importObject := wasmer.NewImportObject() fmt.Println("Instantiating module...") // Let's instantiate the Wasm module. instance, err := wasmer.NewInstance(module, importObject) if err != nil { panic(fmt.Sprintln("Failed to instantiate the module:", err)) }
Please refer to the examples and documentation to learn more about the changes.
0.3.1
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)
Fixed
0.2.0
Features
-
#38 Support import descriptors (@Hywan)
var module, _ = wasm.Compile(bytes) assert.Equal(…, "log_message", module.Imports[0].Name) assert.Equal(…, "env", module.Imports[0].Namespace)
-
#37 Support export descriptors (@Hywan)
var module, _ = wasm.Compile(bytes) assert.Equal(…, "sum", module.Exports[7].Name)
-
#34 Support module serialization and deserialization (@Hywan)
// Compiles the bytes into a WebAssembly module. module1, _ := wasm.Compile(GetBytes()) defer module1.Close() // Serializes the module into a sequence of bytes. serialization, _ := module1.Serialize() // Do something with `serialization`. // Then later… // Deserializes the module. module2, _ := wasm.DeserializeModule(serialization) defer module2.Close() // And enjoy! // Instantiates the WebAssembly module. instance, _ := module2.Instantiate() defer instance.Close() // Gets an exported function. sum, functionExists := instance.Exports["sum"] fmt.Println(functionExists) // Calls the `sum` exported function with Go values. result, _ := sum(1, 2) fmt.Println(result) // Output: // true // 3
-
#33 Add
Compile
,Module.Instantiate*
andModule.Close
(@Hywan) -
#30 Support instance context data (@Hywan)
//export logMessageWithContextData func logMessageWithContextData(context unsafe.Pointer, pointer int32, length int32) { var instanceContext = wasm.IntoInstanceContext(context) var memory = instanceContext.Memory().Data() var logMessage = (*logMessageContext)(instanceContext.Data()) logMessage.message = string(memory[pointer : pointer+length]) } type logMessageContext struct { message string } func testImportInstanceContextData(t *testing.T) { imports, err := wasm.NewImports().Append("log_message", logMessageWithContextData, C.logMessageWithContextData) assert.NoError(t, err) instance, err := wasm.NewInstanceWithImports(getImportedFunctionBytes("log.wasm"), imports) assert.NoError(t, err) defer instance.Close() contextData := logMessageContext{message: "first"} instance.SetContextData(unsafe.Pointer(&contextData)) doSomething := instance.Exports["do_something"] result, err := doSomething() assert.NoError(t, err) assert.Equal(t, wasm.TypeVoid, result.GetType()) assert.Equal(t, "hello", contextData.message) }
-
#29 Add
Imports.Namespace
to set the current import namespace (@Hywan)// By default, the namespace is `"env"`. Change it to `"ns"`. wasm.NewImports().Namespace("ns").Append("f", f, C.f)
Bug/security fixes
Documentation/Test
- #51 Test that all Wasm types can be used in imported functions (@Hywan)
- #36 Improve the Benchmarks Section (@Hywan)
- #32 Move examples in the root directory for godoc.org (@Hywan)
- #31 Fix example namespaces for godoc.org (@Hywan)
- #30 Increase the
cgocheck
level (@Hywan)