Build golang binaries for different system & arch

You can build runnable binaries for different Operating Systems and Arch even you are not in that OS and Arch.

Makefile samples:

1
2
3
4
5
6
7
8
9
10
11
all:
# macbook m1
GOOS=darwin GOARCH=arm64 go build -o build/darwin-arm64-main
# rasperry pi
GOOS=linux GOARCH=arm go build -o build/linux-arm-main
# common linux server
GOOS=linux GOARCH=amd64 go build -o build/linux-amd64-main
# common windows 64bit
GOOS=windows GOARCH=amd64 go build -o build/windows-amd64-main
clean:
rm build/*

Reference