Go Beyond the Server: Compiling Go for Microcontrollers and WebAssembly
You've written Go for years, but what happens when you want to run it on a chip the size of your fingernail or ship it as a WebAssembly module? The standard toolchain isn't built for that. TinyGo is a Go compiler designed specifically for the small places—microcontrollers, WebAssembly, and command-line tools—and it's worth a look if your projects have outgrown the data center.
What It Does
TinyGo is an alternative Go compiler. Rather than replacing everything, it reuses the libraries from the Go language tools and pairs them with LLVM to compile Go programs for targets the standard compiler doesn't handle well. That means your Go source stays Go—same syntax, same familiar packages—but the output is small enough and structured in a way that suits embedded hardware and WebAssembly runtimes.
The project covers three main areas. On the embedded side, it supports a long list of microcontroller boards. For the web, it compiles to both WASM (for browsers) and WASI (for servers and edge devices). And it works for ordinary command-line tools too. The compiler runs on Linux, macOS, and Windows, with Docker and Nix builds available as well.
Why It's Cool
-
One program, many boards. The README's blink example is the clearest demonstration of the appeal. You write a single program that configures
machine.LED, toggles it withtime.Sleep, and it compiles and runs without modification on an Arduino Uno, an Adafruit Circuit Playground Express, a Seeed Studio XIAO-ESP32S3, or any other supported board with a built-in LED. You just pick a different target flag. That's a genuinely nice abstraction—themachinepackage hides the hardware differences so you don't rewrite your code for each board. -
Flashing is a one-liner. Compiling and flashing to an Arduino Uno is
tinygo flash -target arduino-uno examples/blinky1. No separate toolchain dance, no manual upload step in a different program. For anyone who's spent an afternoon fighting embedded build systems, that brevity matters. -
WebAssembly without the ceremony. The WASM story is similarly direct. A function annotated with
//go:wasmexportcompiles to a.wasmfile with a single build command, and it runs on Fastly Compute, Fermyon Spin, wazero, and other runtimes. TinyGo also supports the Go 1.24+ environment-variable syntax (GOOS=wasip1 GOARCH=wasm), so if you prefer the standard convention, you can use it. -
Honest about the sharp edges. The README notes that WASI tests run through
tinygo testhave read/write access to the host filesystem and are not sandboxed, with a plain warning to only run tests you trust. That kind of transparency is refreshing—it tells you the tool is built by people who know where the boundaries are.
How to Try It
-
Start with the getting started instructions at tinygo.org/getting-started. Installation details live there rather than in the README.
-
Clone the repository and look at the examples:
git clone https://github.com/tinygo-org/tinygo
cd tinygo
- If you have a supported board, try the blink example with the appropriate target:
tinygo flash -target arduino-uno examples/blinky1
- For WebAssembly, write a small exported function and build it:
tinygo build -buildmode=c-shared -o add.wasm -target=wasip1 add.go
- Explore the full repository at github.com/tinygo-org/tinygo for board support details and the rest of the documentation. If the project proves useful, there's an OpenCollective page for financial contributions.
Final Thoughts
TinyGo isn't trying to replace the standard Go compiler—it's filling a gap the standard toolchain leaves open. If you're doing embedded work, prototyping for WebAssembly, or just curious whether your Go skills transfer to a microcontroller, this is the project to check out. The abstraction over boards and the direct WASM build commands are the practical wins. It's a focused tool with a clear purpose, and the README makes no promises it can't keep.
Follow @githubprojects for more developer tools and open source projects.