generated from jfrog/jfrog-cli-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-binary.sh
executable file
·35 lines (27 loc) · 892 Bytes
/
build-binary.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash
# Script inspired by https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04
errorExit () {
echo; echo "ERROR: $1"; echo
exit 1
}
BIN=metrics-viewer
rm -rf bin
mkdir -p bin
echo "Building $BIN"
platforms=("darwin/amd64" "linux/arm64" "linux/amd64" "windows/amd64" "windows/386")
for p in "${platforms[@]}"; do
platform_array=(${p//\// })
GOOS=${platform_array[0]}
GOARCH=${platform_array[1]}
echo -e "\nBuilding"
echo "OS: $GOOS"
echo "ARCH: $GOARCH"
final_name=$BIN'-'$GOOS'-'$GOARCH
if [ "$GOOS" = "windows" ]; then
final_name+='.exe'
fi
env GOOS="$GOOS" GOARCH="$GOARCH" go build -o bin/$final_name . || errorExit "Building $final_name failed"
done
echo -e "\nDone!\nThe following binaries were created in the bin/ directory:"
ls -1 bin/
echo