-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbuild-binary.sh
More file actions
executable file
·36 lines (28 loc) · 954 Bytes
/
build-binary.sh
File metadata and controls
executable file
·36 lines (28 loc) · 954 Bytes
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
36
#!/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=sonar-scan-extractor
rm -rf bin
mkdir -p bin
echo "Building $BIN"
#platforms=("darwin/amd64" "linux/arm64" "linux/amd64" "windows/amd64" "windows/386")
platforms=("linux/arm64" "linux/amd64" "darwin/arm64" )
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