Skip to main content

WasmEdge Go SDK Introduction

The following is the guide to working with the WasmEdge Go API. You can embed the WasmEdge into your go application through the WasmEdge Go API.

Set up Environment for embedding WASM functions into your go application

Install and build WasmEdge and WasmEdge Go SDK

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

Meanwhile, please ensure you have installed WasmEdge with the same WasmEdge-go release version.

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

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

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

Build WasmEdge-go Extensions

note

The WasmEdge extensions have been deprecated after the 0.12.1 version. Please use the corresponding plug-ins after the 0.13.0 version.

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.

Toolchain for Compile the Source Code to WASM Bytecode

To embed WasmEdge into your go application and run the WASM function, we still need language toolchain to compile the source code to WASM bytecode.

Examples

API References