-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbuild-backend
executable file
·67 lines (54 loc) · 1.27 KB
/
build-backend
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
#!/usr/bin/env bash
# Exit build script on first failure.
set -e
# Echo commands.
set -x
if [[ -z $1 ]]; then
MODE='prod'
else
MODE="$1"
fi
PLATFORM="${TARGETPLATFORM:-linux/amd64}"
# Exit on unset variable.
set -u
GO_BUILD_TAGS=()
BINARY='./bin/logpaste'
GO_BUILD_TAGS+=('netgo')
# Disable dynamically-loaded extensions, which cause a compile time warning.
# https://www.arp242.net/static-go.html
GO_BUILD_TAGS+=('sqlite_omit_load_extension')
if [[ "${MODE}" != 'prod' ]]; then
BINARY="${BINARY}-${MODE}"
GO_BUILD_TAGS+=("${MODE}")
fi
readonly BINARY
readonly GO_BUILD_TAGS
readonly GOOS='linux'
export GOOS
if [ "${PLATFORM}" = 'linux/amd64' ]; then
GOARCH='amd64'
elif [ "${PLATFORM}" = 'linux/arm/v7' ]; then
GOARCH='arm'
elif [ "${PLATFORM}" = 'linux/arm64' ]; then
GOARCH='arm64'
else
echo "Unsupported platform: ${PLATFORM}"
exit 1
fi
readonly GOARCH
export GOARCH
# Join together build tags
BUILD_TAGS_JOINED=""
for tag in "${GO_BUILD_TAGS[@]}"; do
BUILD_TAGS_JOINED+=" $tag"
done
# Trim leading space.
BUILD_TAGS_JOINED="${BUILD_TAGS_JOINED# }"
readonly BUILD_TAGS_JOINED
# cgo is required for mattn/go-sqlite3.
export CGO_ENABLED=1
go build \
-tags "${BUILD_TAGS_JOINED}" \
-ldflags '-w -extldflags "-static"' \
-o "${BINARY}" \
cmd/logpaste/main.go