Skip to content

Instantly share code, notes, and snippets.

@porfirion
Created April 28, 2021 13:40
Show Gist options
  • Save porfirion/cd30b8e690baed29940c08c66c6b466d to your computer and use it in GitHub Desktop.
Save porfirion/cd30b8e690baed29940c08c66c6b466d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ $# -eq 0 ]
then
echo "Usage: $0 DIRECTORY"
echo " DIRECTORY is a go project directory to build"
exit 1
fi
cd $1 > /dev/null
readonly ROOT=`pwd`
readonly EXE_NAME=$(basename "$ROOT")
echo "Building in dir $ROOT"
GOOSES=(linux windows darwin darwin)
GOARCHS=(amd64 amd64 amd64 arm64)
for i in ${!GOOSES[@]};
do
OS=${GOOSES[i]}
ARCH=${GOARCHS[i]}
FULL_EXE_NAME="$EXE_NAME-$OS-$ARCH"
echo "Will build $FULL_EXE_NAME"
GOOS=$OS GOARCH=$ARCH go build -o "$FULL_EXE_NAME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment