-
Notifications
You must be signed in to change notification settings - Fork 175
/
build.sh
52 lines (43 loc) · 1.18 KB
/
build.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# target platform array
platforms=(
"windows/amd64"
"darwin/amd64"
"linux/386"
"linux/amd64"
"linux/arm/6"
"linux/arm/7"
"linux/arm64"
"linux/ppc64le"
"linux/s390x"
)
# output directory
output_dir="build"
# make sure the output directory exists
mkdir -p "$output_dir"
# compile for each target platform
for platform in "${platforms[@]}"; do
IFS='/' read -r -a platform_split <<<"$platform"
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
GOARM=${platform_split[2]}
output_name="h-ui-${GOOS}-${GOARCH}"
if [ "$GOARCH" == "arm" ]; then
output_name+="v${GOARM}"
fi
# add the appropriate extension
if [ "$GOOS" == "windows" ]; then
output_name+=".exe"
fi
echo "Building for $GOOS/$GOARCH ${GOARM:-}"
build_env="CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH"
[ "$GOARCH" == "arm" ] && build_env+=" GOARM=$GOARM"
env $build_env go build -o "$output_dir/$output_name" -trimpath -ldflags "-s -w"
if [ $? -ne 0 ]; then
echo "Error occurred during building for $GOOS/$GOARCH ${GOARM:-}"
exit 1
fi
done
echo "All builds completed successfully!"