Skip to main content

Go

Build WebAssembly applications with Go using TinyGo and Wasmrun.

Overview

Go supports WebAssembly through TinyGo, a Go compiler designed for small places. Wasmrun's wasmgo plugin makes it easy to compile and run Go projects as WebAssembly.

Prerequisites

Plugin Installation

wasmrun plugin install wasmgo

Quick Start

# Create project
mkdir my-go-wasm && cd my-go-wasm
go mod init my-go-wasm

# Create main.go
cat > main.go << 'EOF'
package main

import "fmt"

func main() {
fmt.Println("Hello from Go WebAssembly!")
}
EOF

# Run with Wasmrun
wasmrun run . --watch

Native Execution

# Build for WASI
tinygo build -target=wasi -o app.wasm .

# Execute
wasmrun exec app.wasm

Example: examples/go-hello

Additional Resources