Created
June 28, 2018 10:32
-
-
Save arush-sal/f3318583d458f2692c94fdd58098205b to your computer and use it in GitHub Desktop.
A simple bash script from cross compiling Go binaries by Marko Mudrinić. As found at: https://do.co/2yPiw9b
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/env bash | |
package=$1 | |
if [[ -z "$package" ]]; then | |
echo "usage: $0 <package-name>" | |
exit 1 | |
fi | |
package_split=(${package//\// }) | |
package_name=${package_split[-1]} | |
platforms=("linux/amd64" "linux/386" "darwin/amd64" "darwin/386") | |
for platform in "${platforms[@]}" | |
do | |
platform_split=(${platform//\// }) | |
GOOS=${platform_split[0]} | |
GOARCH=${platform_split[1]} | |
output_name=$package_name'-'$GOOS'-'$GOARCH | |
echo "Compiling $output_name..." | |
env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package | |
echo -e "Compilation of $output_name done.\n" | |
if [ $? -ne 0 ]; then | |
echo 'An error has occurred! Aborting the script execution...' | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment