Skip to content

Commit

Permalink
Add script for building with multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
xoltia committed Oct 10, 2023
1 parent 4fd197a commit 0208b69
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/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]}

output_dir="bin"
platforms=("windows/amd64" "linux/amd64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi

echo "Building $package for $GOOS/$GOARCH..."

env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_dir/$output_name $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done

0 comments on commit 0208b69

Please sign in to comment.