bytecodealliance/wasmtime-go

GitHub: bytecodealliance/wasmtime-go

Stars: 903 | Forks: 97

wasmtime-go

Go embedding of Wasmtime

A Bytecode Alliance project

CI status Documentation Code Coverage

## Installation go get -u github.com/bytecodealliance/wasmtime-go/v45@v45.0.1 Be sure to check out the [API documentation][api]! This Go library uses CGO to consume the C API of the [Wasmtime project][wasmtime] which is written in Rust. Precompiled binaries of Wasmtime are checked into this repository on tagged releases so you won't have to install Wasmtime locally, but it means that this project only works on Linux x86\_64, macOS x86\_64 , and Windows x86\_64 currently. Building on other platforms will need to arrange to build Wasmtime and use `CGO_*` env vars to compile correctly. This project has been tested with Go 1.13 or later. If you are a bazel user, add following to your WORKSPACE file: go_repository( name = "com_github_bytecodealliance_wasmtime_go", importpath = "github.com/bytecodealliance/wasmtime-go/v45", version = "v45.0.1", ) ## Usage A "Hello, world!" example of using this package looks like: package main import ( "fmt" "github.com/bytecodealliance/wasmtime-go/v45" ) func main() { // Almost all operations in wasmtime require a contextual `store` // argument to share, so create that first store := wasmtime.NewStore(wasmtime.NewEngine()) // Compiling modules requires WebAssembly binary input, but the wasmtime // package also supports converting the WebAssembly text format to the // binary format. wasm, err := wasmtime.Wat2Wasm(` (module (import "" "hello" (func $hello)) (func (export "run") (call $hello)) ) `) check(err) // Once we have our binary `wasm` we can compile that into a `*Module` // which represents compiled JIT code. module, err := wasmtime.NewModule(store.Engine, wasm) check(err) // Our `hello.wat` file imports one item, so we create that function // here. item := wasmtime.WrapFunc(store, func() { fmt.Println("Hello from Go!") }) // Next up we instantiate a module which is where we link in all our // imports. We've got one import so we pass that in here. instance, err := wasmtime.NewInstance(store, module, []wasmtime.AsExtern{item}) check(err) // After we've instantiated we can lookup our `run` function and call // it. run := instance.GetFunc(store, "run") if run == nil { panic("not a function") } _, err = run.Call(store) check(err) } func check(e error) { if e != nil { panic(e) } } And after that you should be good to go! ### Release Checklist First run: $ python3 ci/download-wasmtime.py $ go test Make sure everything passes at the current version. Next run: $ git ls-files | xargs sed -i 's/v16/v17/g' $ python3 ci/download-wasmtime.py $ go test Fix all errors and such and then commit and make a PR. Once merged checkout `main` and do: $ rm .gitignore $ python3 ci/download-wasmtime.py $ git add . $ git commit -m 'v45.0.0 release artifacts' $ git tag v45.0.0 and push up the tag
标签:EVTX分析