WasmEdge Go SDK

The followings are the guides to working with the WasmEdge Go API. You can embed the WasmEdge into your go application through the WasmEdge Go API.

Getting Started

The WasmEdge-go requires golang version >= 1.16. Please check your golang version before installation. You can download golang here.

$ go version
go version go1.16.5 linux/amd64

Meantime, please make sure you have installed the WasmEdge shared library with the same WasmEdge-go release version.

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.10.0

If you need the TensorFlow or Image extension for WasmEdge-go, please install the WasmEdge with extensions:

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.10.0 -e tensorflow,image

Noticed that the TensorFlow and Image extensions are only for the Linux platforms.

Install the WasmEdge-go package and build in your Go project directory:

go get github.com/second-state/WasmEdge-go/wasmedge@v0.10.0
go build

WasmEdge-go Extensions

By default, the WasmEdge-go only turns on the basic runtime.

WasmEdge-go has the following extensions:

  • TensorFlow

    • This extension supports the host functions in WasmEdge-tensorflow.

    • To install the tensorflow extension, please use the -e tensorflow flag in the WasmEdge installer command.

    • For using this extension, the tag tensorflow when building is required:

      go build -tags tensorflow
      
  • Image

    • This extension supports the host functions in WasmEdge-image.

    • To install the image extension, please use the -e image flag in the WasmEdge installer command.

    • For using this extension, the tag image when building is required:

      go build -tags image
      

You can also turn on the multiple extensions when building:

go build -tags image,tensorflow

For examples, please refer to the example repository.

WasmEdge AOT Compiler in Go

The go_WasmAOT example demonstrates how to compile a WASM file into a native binary (AOT compile) from within a Go application.

Examples