Skip to content

Instantly share code, notes, and snippets.

@slashtechno
Last active June 16, 2022 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slashtechno/e709a6fd3ac157af27f1315ef5b64032 to your computer and use it in GitHub Desktop.
Save slashtechno/e709a6fd3ac157af27f1315ef5b64032 to your computer and use it in GitHub Desktop.
Script to cross compile a Go file
#!/usr/bin/bash
# Edited code from https://opensource.com/article/21/1/go-cross-compiling
# xgo (https://github.com/techknowlogick/xgo) is a better solution for programs which use more than one Go file
archsLinux=(amd64 arm64 arm)
archsWindows=(amd64 arm arm64 386)
programName=
for arch in ${archsLinux[@]}
do
env GOOS=linux GOARCH=${arch} go build -o ../binaries/${programName}_linux_${arch} main.go
done
for arch in ${archsWindows[@]}
do
env GOOS=windows GOARCH=${arch} go build -o ../binaries/${programName}_windows_${arch}.exe main.go
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment