Go

    You must have on your machine before installing TinyGo. Go v1.17 or above is recommended. For Ubuntu or other Debian-based Linux systems on x86 processors, you could use the following command line to install TinyGo. For other platforms, please refer to TinyGo docs.

    Next, run the following command line to check out if the installation is successful.

    1. tinygo version 0.21.0 linux/amd64 (using go version go1.16.7 and LLVM version 11.0.0)

    The simple Go app has a main() function to print a message to the console. The source code in main.go file is as follows.

    1. package main
    2. func main() {
    3. }

    Next, compile the main.go program to WebAssembly using TinyGo.

    You will see a file named hello.wasm in the same directory. This is a WebAssembly bytecode file.

    You can run it with the .

    1. $ wasmedge hello.wasm
    2. Hello TinyGo from WasmEdge!
    1. func main(){
    2. }
    3. //export fibArray
    4. func fibArray(n int32) int32{
    5. arr := make([]int32, n)
    6. for i := int32(0); i < n; i++ {
    7. switch {
    8. arr[i] = i
    9. default:
    10. arr[i] = arr[i-1] + arr[i-2]
    11. }
    12. }
    13. }

    Next, compile the main.go program to WebAssembly using TinyGo.

    You will see a file named fib.wasm in the same directory. This is a WebAssembly bytecode file.

    You can run it with the WasmEdge CLI in its --reactor mode. The command line arguments that follow the wasm file are the function name and its call parameters.

    1. $ wasmedge --reactor fib.wasm fibArray 10
    2. 34
    1. $ wasmedgec hello.wasm hello.wasm
    2. $ wasmedge hello.wasm
    3. Hello TinyGo from WasmEdge!

    For the --reactor mode,