GOOS=wasip1 GOARCH=wasm go build ...
WASI is still in preview and is missing some key features, e.g. the ability to create sockets. Some WebAssembly runtimes have taken the initiative to extend the WASI preview, enabling a wider range of applications to run as WebAssembly modules.Today, we're open sourcing our WASI library and sockets extension for the Wazero WebAssembly runtime (https://wazero.io).
https://github.com/stealthrocket/wasi-go
The WASI library includes a wasirun command that can be used to run server-side WebAssembly applications compiled with Go: ~ $ cat << EOF > hello.go
package main
import "fmt"
func main() { fmt.Println("Hello, World!") }
EOF
~ $ GOOS=wasip1 GOARCH=wasm gotip build -o hello.wasm hello.go
~ $ wasirun hello.wasm
Hello, World!
Non-blocking I/O and basic networking is also supported when compiling apps from Go, e.g. see https://gist.github.com/chriso/6c71e968ef1002981a6ff46ceaa39.... Until Go v1.21 is released in August, you can use gotip (https://pkg.go.dev/golang.org/dl/gotip) to try GOOS=wasip1 features.The provided sockets extension is compatible with the WasmEdge (https://wasmedge.org) runtime, allowing wasirun to run more complicated server-side applications compiled from C/C++/Rust/Zig for WasmEdge.
We have many exciting use cases for WebAssembly and WASI planned and can't wait to share them with you.