This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Go · Archive · Week 7 · Feb 10 – 16, 2025

Extensible Wasm Applications with Go

Nice to knowtooling

What changed
Go 1.24 adds function export and reactor mode support for WebAssembly.
Production impact
The source does not say.
Try it
Build a small Wasm module that exports a Go function and run it in a browser.
Source
go.dev/blog/wasmexport

Understand it, then run it

Run it now

Todaygo
// This program demonstrates that the //go:wasmexport directive is ignored
// in Go 1.27.1. The function is not exported to a WebAssembly module,
// so we simply call it directly from Go and print the result.

package main

import "fmt"

//go:wasmexport add
func add(a, b int32) int32 { return a + b }

func main() {
	// Call the function directly; it behaves normally in Go.
	res := add(3, 4)
	fmt.Printf("add(3, 4) = %d\n", res)
}

What it printed when we ran it on Go 1.27.1

add(3, 4) = 7

After the change ships

go · the proposal's code; it does not compile until the change ships

// This code uses the go:wasmexport directive and builds a WASI reactor.
// It will not compile until Go 1.24 is released.

package main

//go:wasmexport add
func add(a, b int32) int32 {
	return a + b
}

func main() {
	// No runtime logic needed; the host will call _initialize and then
	// invoke the exported function "add" as many times as desired.
}

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed