Last active
January 23, 2023 11:32
-
-
Save ipid/13cc9fe1c4c3dce2ef1225194eb726bc to your computer and use it in GitHub Desktop.
A simple Bash script that cross-compile Go code to all supported platform, generate zips and print checksums. Originally wrote for ytarchive.
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
#!/bin/bash | |
export CGO_ENABLED=0 | |
if [[ -n "$1" ]]; then | |
LDFLAGS="-X main.Commit=-$(git rev-parse --short HEAD)" | |
else | |
LDFLAGS="" | |
fi | |
go mod download & rm -f build/*.zip & readarray -t goSupported <<< "$(go tool dist list)" | |
wait | |
for tuple in "${goSupported[@]}"; do | |
readarray -t -d '/' osArch <<< ${tuple} | |
GOOS=$(echo ${osArch[0]} | xargs) | |
GOARCH=$(echo ${osArch[1]} | xargs) | |
mkdir -p build/$GOOS-$GOARCH | |
if [[ $GOOS == "windows" ]]; then | |
binaryFileName="ytarchive.exe" | |
else | |
binaryFileName="ytarchive" | |
fi | |
GOOS=$GOOS GOARCH=$GOARCH go build -o build/$GOOS-$GOARCH/$binaryFileName -ldflags "$LDFLAGS" && \ | |
7z a -tzip -mx=5 build/ytarchive-$GOOS-$GOARCH.zip ./build/$GOOS-$GOARCH/$binaryFileName & | |
done | |
wait | |
cd ./build | |
printf "\nChecksums:\n" | |
sha256sum *.zip | tee SHA256CHKSUMS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment