Repository navigation
Expand file tree
/
Copy pathBuild.sh
More file actions
executable file
·182 lines (169 loc) · 5.5 KB
/
Copy pathBuild.sh
File metadata and controls
executable file
·182 lines (169 loc) · 5.5 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/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=
fuzz_cmake_option=
threads_ninja_option=
loadavg_ninja_option=
DO_BUILD=true
while getopts "s:b:i:j:l:hXTAUFRn" 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
;;
F)
# The fuzzer requires Address sanitizer to be enabled. Due to a
# conflict with a target name in couchdb we currently set it to
# kv-commit-validation build which builds just a subset
# of the Couchbase Server codebase.
fuzz_cmake_option="-D CB_ADDRESSSANITIZER=1 -D FUZZTEST_FUZZING_MODE=ON -D COUCHBASE_KV_COMMIT_VALIDATION=1"
;;
R)
CMAKE_BUILD_TYPE=RelWithDebInfo
;;
n)
DO_BUILD=false
;;
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
-F Enable fuzzing
-R Set build type to RelWithDebInfo
-n No build - run CMake only
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}"
# Allow the user to provide extra CMake options via ~/.cbbuildrc. Each
# non-comment (non "#") line is passed to CMake as a "-D" option. If the
# file is newer than CMakeCache.txt we force CMake to reconfigure so the
# new options take effect.
force_cmake_config=false
cbbuildrc="${HOME}/.cbbuildrc"
if [ -f "${cbbuildrc}" ]
then
while IFS= read -r line || [ -n "${line}" ]
do
case "${line}" in
\#*|'') continue ;;
esac
EXTRA_CMAKE_OPTIONS="${EXTRA_CMAKE_OPTIONS} -D ${line}"
done < "${cbbuildrc}"
if [ "${cbbuildrc}" -nt "${build_root}/CMakeCache.txt" ]
then
force_cmake_config=true
fi
fi
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 ] || ${force_cmake_config}
then
cmake -G Ninja \
${macos_cross_compilation_flags} \
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
-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} ${fuzz_cmake_option} \
${source_root} \
|| errexit "Failed to generate build configuration"
fi
if ${DO_BUILD}
then
ninja ${threads_ninja_option} ${loadavg_ninja_option} install "$@" || errexit "Build failed"
fi