Skip to content

Instantly share code, notes, and snippets.

@theGeekPirate
Last active August 8, 2020 16:56
Show Gist options
  • Save theGeekPirate/c73491634e4680d80c41 to your computer and use it in GitHub Desktop.
Save theGeekPirate/c73491634e4680d80c41 to your computer and use it in GitHub Desktop.
Builds a Go debug binary for all supported platforms (excluding mobile)
#!/bin/sh
#From https://golang.org/doc/install/source#environment
platforms=(aix android darwin dragonfly freebsd illumos js linux netbsd openbsd plan9 solaris windows)
arches=(386 amd64 arm arm64 mips mipsle mips64 mips64le ppc64 ppc64le s390x wasm)
#.go file to build
test "$1" && target="$1"
if ! test "$target"; then
target="main.go"
fi
binaryName="$2"
for platform in "${platforms[@]}"; do
for arch in "${arches[@]}"; do
goos=${platform}
goarch=${arch}
output="$binaryName"
output="$(basename $target | sed 's/\.go//')"
[[ "windows" == "$goos" ]] && output="$output.exe"
destination="$(dirname $target)/builds/debug/$goos/$goarch/$output"
echo -e "\e[00;33mGOOS=$goos GOARCH=$goarch go build -o $destination $target\e[00m"
GOOS=$goos GOARCH=$goarch go build -o "$destination" "$target"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment