Last active
June 16, 2022 20:57
-
-
Save slashtechno/e709a6fd3ac157af27f1315ef5b64032 to your computer and use it in GitHub Desktop.
Script to cross compile a Go file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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