-
Notifications
You must be signed in to change notification settings - Fork 22
/
build.sh
executable file
·311 lines (261 loc) · 9.15 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#! /usr/bin/env bash
#
# Copyright (c) 2019 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
# Use CC and CXX environment variables to use custom compilers.
start_time=$(date +%s)
# Always use bash
shell=$(basename $(readlink /proc/$$/exe))
if [ ! x$shell = x"bash" ] && [[ x$shell != x"qemu-aarch64"* ]]
then
bash $0 $@
exit $?
fi
this_dir=$(dirname $(readlink -f $0))
# CMake and GCC version checking
function version_cmp {
mapfile -t left < <( echo $1 | tr . '\n' )
mapfile -t right < <( echo $2 | tr . '\n')
local i
for i in ${!left[@]}
do
local lv=${left[$i]}
local rv=${right[$i]}
[[ -z $rv ]] && { echo $lv; return; }
[[ $lv -ne $rv ]] && { echo $((lv - rv)); return; }
done
((i++))
rv=${right[$i]}
[[ ${#right[@]} -gt ${#left[@]} ]] && { echo $((0-rv)); return; }
}
function check_cmake {
hash cmake &> /dev/null || { echo "No cmake found." 1>&2 ; return 1; }
local cmake_version=$(cmake --version | head -1 | cut -d ' ' -f 3)
local least_cmake_version=3.14.0
if [[ $(version_cmp $cmake_version $least_cmake_version) -lt 0 ]]
then
echo "cmake $least_cmake_version or higher required, but only found $cmake_version" 1>&2
return 1
fi
return 0
}
function check_cxx {
# TODO To consider clang++
local cxx_cmd
hash g++ &> /dev/null && cxx_cmd=g++
[[ -n $CXX ]] && cxx_cmd=$CXX
[[ -z $cxx_cmd ]] && { echo "No C++ compiler found" 1>&2; exit 1; }
cxx_version=$($cxx_cmd -dumpfullversion -dumpversion 2>/dev/null)
local least_cxx_version=7.5.0
if [[ $(version_cmp $cxx_version $least_cxx_version) -lt 0 ]]
then
echo "g++ $least_cxx_version or higher required, but you have $cxx_version" 1>&2
exit 1
fi
}
check_cxx
source $this_dir/.env
# Directories setup
cur_dir=`pwd`
source_dir=$this_dir/project
build_root=$cur_dir
build_dir=$build_root/build
package_dir=$build_root/packages
prefix=$1
install_dir=${prefix:-$build_root/install}
download_dir=$build_root/tarballs
source_tar_name=nebula-third-party-src-$VERSION.tgz
source_url=$URL_BASE/${source_tar_name}
logfile=$build_root/build.log
cxx_cmd=${CXX:-g++}
gcc_version=$(${CXX:-g++} -dumpfullversion -dumpversion)
abi_version=$($this_dir/cxx-compiler-abi-version.sh)
libc_version=$(ldd --version | head -1 | cut -d ' ' -f4 | cut -d '-' -f1)
export PATH=$install_dir/bin:$PATH
export PKG_CONFIG_PATH=$install_dir/lib/pkgconfig:$install_dir/lib64/pkgconfig:$PKG_CONFIG_PATH
# Exit on any failure here after
set -e
set -o pipefail
trap '[[ $? -ne 0 ]] && echo "Building failed, see $logfile for more details." 1>&2' EXIT
# Allow to customize compilers
[[ -n ${CC} ]] && C_COMPILER_ARG="-DCMAKE_C_COMPILER=${CC}"
[[ -n ${CXX} ]] && CXX_COMPILER_ARG="-DCMAKE_CXX_COMPILER=${CXX}"
[[ ${disable_cxx11_abi} -ne 0 ]] && DISABLE_CXX11_ABI="-DDISABLE_CXX11_ABI=1"
export disable_cxx11_abi
# Download source archives if necessary
mkdir -p $build_root
cd $build_root
if [[ -f $source_tar_name ]]
then
checksum=$(md5sum $source_tar_name | cut -d ' ' -f 1)
fi
# NOTE Please adjust the expected checksum once the source tarball changed
if [[ ! $checksum = d466687c0f2946fd300e8c2bca42a5d7 ]]
then
rm -f $source_tar_name
hash wget &> /dev/null && download_cmd="wget -c"
if [[ -z $download_cmd ]]
then
echo "'wget' not found for downloading" 1>&2;
elif ! bash -c "$download_cmd $source_url"
then
# Resort to the builtin download method of cmake on failure
echo "Download from $source_url failed." 1>&2
else
echo "Source of third party was downdloaded to $build_root"
echo -n "Extracting into $download_dir..."
tar -xzf $source_tar_name
echo "done"
fi
else
tar -xzf $source_tar_name
fi
# Check cmake
if ! check_cmake; then
echo "Need to build cmake"
mkdir -p $build_dir/build-info
cmake_log_file=$build_dir/build-info/cmake-build.log
cmake_source_tar=$build_root/tarballs/cmake-v3.21.4.tar.gz
# Check the downloaded source tarball
if [[ -f $cmake_source_tar ]]; then
cmake_checksum=$(md5sum $cmake_source_tar | cut -d ' ' -f 1)
fi
if [[ ! $cmake_checksum = 3747c1a51d4a7ad61f08862481437264 ]]; then
# Try to download cmake tar ball
hash wget &> /dev/null && download_cmd="wget -c"
cmake_source_url="https://gitlab.kitware.com/cmake/cmake/-/archive/v3.21.4/cmake-v3.21.4.tar.gz"
mkdir -p $build_root/tarballs
cd $build_root/tarballs
if [[ -z $download_cmd ]]; then
echo "'wget' not found for downloading" 1>&2
exit 1
elif ! bash -c "$download_cmd $cmake_source_url"; then
echo "Download from $cmake_source_url failed." 1>&2
exit 1
fi
echo "cmake source code was downloaded to $build_root/tarballs" 1>&2
fi
# Extracting the cmake source file
echo -n "Extracting cmake source into $build_root/build/cmake/source..." 1>&2
mkdir -p $build_root/build/cmake
cd $build_root/build/cmake
if ! mkdir -p source && tar -xzf $cmake_source_tar -C ./source --strip-components=1; then
echo "corrupted" 1>&2
exit 1
fi
echo "done" 1>&2
# Building the cmake
echo "Building cmake from the source code..." 1>&2
cd source
if ! bash -c "./bootstrap --prefix=$install_dir -- -DCMAKE_USE_OPENSSL=OFF && make -j install" 2&> $cmake_log_file; then
echo "Failed to build cmake"
echo " -- Please check $cmake_log_file for detail"
exit 1
fi
cmake_cmd="$install_dir/bin/cmake"
else
cmake_cmd=`which cmake`
fi
echo "Will use this cmake: '$cmake_cmd'"
# Build and install
mkdir -p $build_dir $install_dir $package_dir
cd $build_dir
echo "Starting building third-party libraries"
$cmake_cmd -DDOWNLOAD_DIR=$download_dir \
-DCMAKE_INSTALL_PREFIX=$install_dir \
${C_COMPILER_ARG} ${CXX_COMPILER_ARG} \
${DISABLE_CXX11_ABI} \
$source_dir |& tee $logfile
make |& \
tee -a $logfile | \
{ grep --line-buffered 'Creating\|^Scanning\|Performing\|Completed\|CMakeFiles.*Error' || true; }
end_time=$(date +%s)
# We are going to keep the build files so that next time it does not have to
# re-build everything. If you want to rebuild everything, simply remove the
# build directory
#cd $OLDPWD && rm -rf $build_dir
# Remove all libtool files
find $install_dir -name '*.la' | xargs rm -f
# Remove big unneeded binaries
binaries+=(openssl gss-client dump_syms_mac)
binaries+=(uuclient sim_client)
binaries+=(sclient compile_et)
binaries+=(c_rehash gflags_completions.sh)
binaries+=(curl curl-config)
binaries+=(proxygen_{echo,push,proxy,static,curl})
binaries+=(db_{archive,checkpoint,deadlock,dump,hotbackup,load})
binaries+=(db_{log_verify,printlog,recover,replicate,stat,upgrade,verify})
binaries+=(bzip2 bunzip2 bzip2recover bz{cat,cmp,diff,less,more,grep,egrep,fgrep})
binaries+=(lz4 lz4c lz4cat unlz4 lz{cat,cmp,diff,less,more,grep,egrep,fgrep})
binaries+=(lzma unlzma lzma{dec,info})
binaries+=(zstd zstdgrep)
binaries+=(xz unxz xz{cat,cmp,dec,diff,less,more,grep,egrep,fgrep})
for file in ${binaries[@]}
do
rm -f $install_dir/bin/$file
done
binaries=()
binaries+=(slap{acl,add,auth,cat,dn,index,passwd,schema,test})
for file in ${binaries[@]}
do
rm -f $install_dir/sbin/$file
done
binaries=()
binaries+=(slapd)
for file in ${binaries[@]}
do
rm -f $install_dir/libexec/$file
done
# Strip executables
for file in $install_dir/bin/*
do
file $file | grep ELF >/dev/null && strip --strip-unneeded $file
done
# Remove unneeded static libraries
#libs+=(libmstch.a libmustache_lib.a)
#for lib in ${libs[@]}
#do
# rm -f $install_dir/lib/$lib
# rm -f $install_dir/lib64/$lib
#done
# Remove CMake configs of boost
rm -rf $install_dir/lib/cmake/[Bb]oost*
march=$(uname -m)
cat > $install_dir/version-info <<EOF
Package : Nebula Third Party
Version : $VERSION
Date : $(date)
glibc : $libc_version
Arch : $march
Compiler : GCC $gcc_version
C++ ABI : $abi_version
Vendor : VEsoft Inc.
EOF
function make_package {
exec_file=$package_dir/vesoft-third-party-$VERSION-$march-libc-$libc_version-gcc-$gcc_version-abi-$abi_version.sh
echo "Creating self-extractable package $exec_file"
cat > $exec_file <<EOF
#! /usr/bin/env bash
set -e
hash xz &> /dev/null || { echo "xz: Command not found"; exit 1; }
[[ \$# -ne 0 ]] && prefix=\$(echo "\$@" | sed 's;.*--prefix=(\S*).*;\1;p' -rn)
prefix=\${prefix:-/opt/vesoft/third-party/$VERSION}
mkdir -p \$prefix
[[ -w \$prefix ]] || { echo "\$prefix: No permission to write"; exit 1; }
archive_offset=\$(awk '/^__start_of_archive__$/{print NR+1; exit 0;}' \$0)
rm -rf \$prefix/*
tail -n+\$archive_offset \$0 | tar --no-same-owner --numeric-owner -xJf - -C \$prefix
echo "Nebula Third Party has been installed to \$prefix"
exit 0
__start_of_archive__
EOF
cd $install_dir
tar -cJf - * >> $exec_file
chmod 0755 $exec_file
cd $OLDPWD
}
[[ $build_package -ne 0 ]] && make_package
echo
echo "Third parties have been successfully installed to $install_dir"
echo "$((end_time - start_time)) seconds been taken."