-
Notifications
You must be signed in to change notification settings - Fork 0
/
cross.sh
executable file
·119 lines (99 loc) · 1.76 KB
/
cross.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
set -e
SRC=$(realpath $(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd))
NAME="$(basename $SRC).test"
FORCE=false
VERBOSE=false
PLATFORM=$(go env GOOS)
ARCH=$(go env GOARCH)
GOARCH=$ARCH
TAGS=(
)
OPTIND=1
while getopts "a:fvt:" opt; do
case "$opt" in
a) ARCH=$OPTARG ;;
f) FORCE=true ;;
v) VERBOSE=true ;;
t) TAGS=($OPTARG) ;;
esac
done
BUILD=$SRC/build
DIR=$BUILD/$PLATFORM/$ARCH
TAR=tar
EXT=tar.bz2
BIN=$DIR/$NAME
OUT=$DIR
CARCH=
QEMUARCH=
GNUTYPE=
CC=
CXX=
EXTLD=g++
if [[ "$PLATFORM" == "linux" && "$ARCH" != "$GOARCH" ]]; then
case $ARCH in
arm) CARCH=armhf QEMUARCH=arm GNUTYPE=gnueabihf ;;
arm64) CARCH=aarch64 QEMUARCH=aarch64 GNUTYPE=gnu ;;
*)
echo "error: unknown arch $ARCH"
exit 1
;;
esac
LDARCH=$CARCH
if [[ "$ARCH" == "arm" ]]; then
if [ -d /usr/arm-linux-$GNUTYPE ]; then
LDARCH=arm
elif [ -d /usr/arm-none-linux-$GNUTYPE ]; then
LDARCH=arm-none
fi
fi
CC=$LDARCH-linux-$GNUTYPE-gcc
CXX=$LDARCH-linux-$GNUTYPE-c++
EXTLD=$LDARCH-linux-$GNUTYPE-g++
fi
LDFLAGS=(
-s
-w
)
TAGS="${TAGS[@]}"
LDFLAGS="${LDFLAGS[@]}"
echo "APP: $NAME ($PLATFORM/$ARCH)"
echo "BUILD TAGS: $TAGS"
echo "LDFLAGS: $LDFLAGS"
pushd $SRC &> /dev/null
if [ -f $OUT ]; then
echo "REMOVING: $OUT"
rm -rf $OUT
fi
mkdir -p $DIR
echo "BUILDING: $BIN"
# build
echo "BUILD:"
(set -x;
CC=$CC \
CXX=$CXX \
CGO_ENABLED=1 \
GOARCH=$ARCH \
go test \
-a=$FORCE \
-v=$VERBOSE \
-x=$VERBOSE \
-tags="$TAGS" \
-c \
-o $BIN
)
(set -x;
file $BIN
)
if [[ "$PLATFORM" != "windows" ]]; then
(set -x;
chmod +x $BIN
)
fi
# purge disk cache
if [[ "$PLATFORM" == "darwin" && "$CI" == "true" ]]; then
(set -x;
sudo /usr/sbin/purge
)
fi
popd &> /dev/null