-
Notifications
You must be signed in to change notification settings - Fork 46
/
Build.sh
executable file
·142 lines (131 loc) · 4.32 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
# Copyright 2023-Present Couchbase, Inc.
#
# Use of this software is governed by the Business Source License included in
# the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that
# file, in accordance with the Business Source License, use of this software
# will be governed by the Apache License, Version 2.0, included in the file
# licenses/APL2.txt.
# Convenience script to build Couchbase Server
# Dump an error message and terminate
errexit() {
echo "FATAL ERROR: \"${1}\""
exit 1
}
source_root=$(pwd)
build_root=$(pwd)/build
install_root=$(pwd)/install
# The link step may consume a _lot_ of memory as a lot of the programs
# use static linking of C++ objects with a ton of symbols (I've seen
# it go way above 1 GB). To work around the problem of the linker running
# out of memory and fail the build reduce the number of parallel link jobs.
cb_parallel_link_jobs=${CB_PARALLEL_LINK_JOBS-2}
macos_cross_compilation_flags=
tsan_cmake_option=
asan_cmake_option=
ubsan_cmake_option=
threads_ninja_option=
loadavg_ninja_option=
while getopts "s:b:i:j:l:hXTAUR" OPTION; do
case $OPTION in
s)
source_root=${OPTARG}
;;
b)
build_root=${OPTARG}
;;
i)
install_root=${OPTARG}
;;
j)
threads_ninja_option="-j ${OPTARG}"
;;
l)
loadavg_ninja_option="-l ${OPTARG}"
;;
X)
macos_cross_compilation_flags="-D CMAKE_APPLE_SILICON_PROCESSOR=x86_64 -D CMAKE_OSX_ARCHITECTURES=x86_64"
;;
T)
if [ -z "${asan_cmake_option}" ]
then
tsan_cmake_option="-D CB_THREADSANITIZER=1"
else
errexit "Thread sanitizer cannot be used together with Address sanitizer"
fi
;;
U)
ubsan_cmake_option="-D CB_UNDEFINEDSANITIZER=1"
;;
A)
if [ -z "${tsan_cmake_option}" ]
then
asan_cmake_option="-D CB_ADDRESSSANITIZER=1"
else
errexit "Address sanitizer cannot be used together with Thread sanitizer"
fi
;;
R)
CMAKE_BUILD_TYPE=RelWithDebInfo
;;
h)
cat <<EOF
Usage:
-s source_root Source directory (default: ${source_root})
-b build_root Build directory (default: ${build_root})
-i install_root Install directory (default: ${install_root})
-X Set Mac platform to x86_64 (Only needed when
building on Mac running arm64)
-T Enable thread sanitizer
-A Enable address sanitizer
-U Enable undefined behavior sanitizer
-R Set build type to RelWithDebInfo
EOF
exit 0
;;
*)
echo "Incorrect options provided"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
# Verify that we've got ninja in place
if ! which ninja > /dev/null
then
cat << EOF
FATAL ERROR: ninja not installed (or not in path)
install via: brew install ninja
apt install ninja-build
yum install ninja-build
EOF
exit 1
fi
if ! which ccache > /dev/null
then
echo "INFO: Using ccache would speed up the development cycle"
echo " install via: brew install ccache (mac)"
echo " apt install ccache"
echo " yum install ccache"
fi
mkdir -p ${build_root} || errexit "Failed to create build directory: ${build_root}"
cd ${build_root} || errexit "Failed to enter the build directory: ${build_root}"
if [ ${source_root}/tlm/CMakeLists.txt -nt ${source_root}/CMakeLists.txt ]
then
chmod u+w ${source_root}/CMakeLists.txt || errexit "Failed to make ${source_root}/CMakeLists.txt writable"
cp ${source_root}/tlm/CMakeLists.txt ${source_root}/CMakeLists.txt || errexit "Failed to update ${source_root}/CMakeLists.txt"
chmod u-w ${source_root}/CMakeLists.txt || errexit "Failed to make ${source_root}/CMakeLists.txt non-writable"
fi
if [ ! -f build.ninja ] || [ ${source_root}/CMakeLists.txt -nt build.ninja ]
then
cmake -G Ninja \
${macos_cross_compilation_flags} \
-D CMAKE_INSTALL_PREFIX=${install_root} \
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE-DebugOptimized} \
-D CB_PARALLEL_LINK_JOBS=${cb_parallel_link_jobs} \
${EXTRA_CMAKE_OPTIONS} \
${tsan_cmake_option} ${asan_cmake_option} ${ubsan_cmake_option} \
${source_root} \
|| errexit "Failed to generate build configuration"
fi
ninja ${threads_ninja_option} ${loadavg_ninja_option} install "$@" || errexit "Build failed"