#TIL | #Go

July 3, 2021 | 11:38

go tool dist list

Imagine that you want to cross-compile your Go binary from your Mac for a Linux machine that runs on arm64 architecture. With Go, it’s a matter of specifying the GOOS and GOARCH environment variables for go build command.

GOOS=linux GOARCH=arm64 go build main.go

You don’t always know/remember what values for GOOS and GOARCH or you are not even sure if Go supports the target you desire. This is where the command go tool dist list comes in handy, when you run it it will list all the GOOS/GOARCH combinations available for the Go version that you are running.

For example, running this for go1.16.5:

$ go tool dist list

aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
freebsd/arm64
illumos/amd64
ios/amd64
ios/arm64
js/wasm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/riscv64
linux/s390x
netbsd/386
netbsd/amd64
netbsd/arm
netbsd/arm64
openbsd/386
openbsd/amd64
openbsd/arm
openbsd/arm64
openbsd/mips64
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
windows/386
windows/amd64
windows/arm