Last active
April 5, 2024 12:58
-
-
Save theGeekPirate/6e6655941c9485babd08 to your computer and use it in GitHub Desktop.
Builds a Go production (debug info stripped) binary for all supported platforms (excluding mobile)
This file contains hidden or 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
#!/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/production/$goos/$goarch/$output" | |
echo -e "\e[00;33mGOOS=$goos GOARCH=$goarch go build -ldflags \"-w\" -o $destination $target\e[00m" | |
GOOS=$goos GOARCH=$goarch go build -ldflags "-w" -o "$destination" "$target" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment