-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
63 lines (48 loc) · 3.03 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
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
set -e
# Compiled Platform
platforms=("linux/amd64" "linux/arm64")
GO_VERSION_MAJOR=$(go version | sed -e 's/.*go\([0-9]\+\)\..*/\1/')
GO_VERSION_MINOR=$(go version | sed -e 's/.*go[0-9]\+\.\([0-9]\+\)\..*/\1/')
echo "Major golang version [$GO_VERSION_MAJOR] minor golang version [$GO_VERSION_MINOR]"
# Prepare build env
REPO="github.com/wentaojin/dbms"
COMMIT=$(git describe --always --no-match --tags --dirty="-dev")
BUILDTS=$(date '+%Y-%m-%d %H:%M:%S')
GITHASH=$(git rev-parse HEAD)
GITREF=$(git rev-parse --abbrev-ref HEAD)
LDFLAGS="-w -s"
# Add build flags
LDFLAGS+=" -X '$REPO/version.Version=$COMMIT'"
LDFLAGS+=" -X '$REPO/version.BuildTS=$BUILDTS'"
LDFLAGS+=" -X '$REPO/version.GitHash=$GITHASH'"
LDFLAGS+=" -X '$REPO/version.GitBranch=$GITREF'"
echo "Prepare build flags [$LDFLAGS]"
# Go main path
APP_SRC=$(pwd)
DBMS_CLI="$APP_SRC/component/cli/main.go"
DBMS_CLUSTER="$APP_SRC/component/cluster/main.go"
DBMS_MASTER="$APP_SRC/component/master/main.go"
DBMS_WORKER="$APP_SRC/component/worker/main.go"
# Compiled output
gocache="/gocache"
LINUX_AMD64_DIR="$gocache/linux/amd64"
LINUX_ARM64_DIR="$gocache/linux/arm64"
mkdir -p $LINUX_AMD64_DIR
mkdir -p $LINUX_AMD64_DIR
for platform in "${platforms[@]}"; do
IFS='/' read -r XGOOS XGOARCH <<< "$platform"
echo "Compiling for $XGOOS/$XGOARCH..."
if { [ "$XGOOS" == "." ] || [ "$XGOOS" == "linux" ]; } && { [ "$XGOARCH" == "." ] || [ "$XGOARCH" == "amd64" ]; }; then
CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++ GOOS=linux GOARCH=amd64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_AMD64_DIR/dbms-ctl" -ldflags "$LDFLAGS" ${DBMS_CLI}
CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++ GOOS=linux GOARCH=amd64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_AMD64_DIR/dbms-cluster" -ldflags "$LDFLAGS" ${DBMS_CLUSTER}
CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++ GOOS=linux GOARCH=amd64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_AMD64_DIR/dbms-master" -ldflags "$LDFLAGS" ${DBMS_MASTER}
CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++ GOOS=linux GOARCH=amd64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_AMD64_DIR/dbms-worker" -ldflags "$LDFLAGS" ${DBMS_WORKER}
fi
if { [ "$XGOOS" == "." ] || [ "$XGOOS" == "linux" ]; } && { [ "$XGOARCH" == "." ] || [ "$XGOARCH" == "arm64" ]; }; then
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_ARM64_DIR/dbms-ctl" -ldflags "$LDFLAGS" ${DBMS_CLI}
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_ARM64_DIR/dbms-cluster" -ldflags "$LDFLAGS" ${DBMS_CLUSTER}
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_ARM64_DIR/dbms-master" -ldflags "$LDFLAGS" ${DBMS_MASTER}
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 GO111MODULE=on CGO_ENABLED=1 go build -o "$LINUX_ARM64_DIR/dbms-worker" -ldflags "$LDFLAGS" ${DBMS_WORKER}
fi
done