Building a WebAssembly hello-world app using TinyGo + wasip2

Rajat Jindal

Aug 7th 2024, 10:30AM

WebAssembly is the talk of the town, and TinyGo recently added support for wasip2. In this blog, we will walkthrough the steps to implement a WebAssembly Hello World app using TinyGo and run it using Wasmtime.

This blog post has been updated on May 3rd to work with latest version of TinyGo (v0.37.0) and Wasmtime (v0.32.0).

Prerequisites

Install TinyGo

TinyGo recently added support for wasip2, and it is available since v0.33.0 release.

  • Follow the install guide for tinygo.
  • Verify that tinygo is installed successfully
> tinygo version  
tinygo version 0.37.0 darwin/arm64 (using go version go1.24.2 and LLVM version 19.1.2)

Install wasm-tools

wasm-tools provide a number of subcommands for working with wasm modules and components. This is triggered during compilation by tinygo to create a webassembly component.

  • Download and add wasm-tools to your path from their GitHub releases page
  • Verify that wasm-tools is installed successfully
> wasm-tools --version
wasm-tools 1.229.0

Install wasmtime

  • Download and add wasmtime to your path from their GitHub releases page
  • Verify that wasmtime is installed successfully
> wasmtime --version
wasmtime 32.0.0 (d3054950c 2025-04-21)

With that, we are now ready to dive into developing our first hello-world WebAssembly app:

mkdir hello-world
cd hello-world

cat >> main.go <<EOF
package main

import "fmt"

func main() {
    fmt.Println("Hello World !")
}
EOF

Now, we will build it using tinygo:

tinygo build -target=wasip2 -o main.wasm main.go

and finally run it using wasmtime

> wasmtime main.wasm
Hello World !

Congratulations !! You just executed your first app using WebAssembly + TinyGo + Wasmtime.

In the next article, we will discuss how to create a serverless http app using TinyGo + wasip2 and run using wasmtime.