forked from facebookincubator/katran
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_katran.sh
executable file
·658 lines (606 loc) · 19.5 KB
/
build_katran.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
#!/usr/bin/env bash
# Copyright (C) 2018-present, Facebook, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
set -xeo pipefail
NCPUS=$(nproc)
# default to 4 threads for a reasonable build speed (e.g in travis)
if (( NCPUS < 4 )); then
NCPUS=4
fi
ROOT_DIR=$(pwd)
# Useful constants
COLOR_RED="\033[0;31m"
COLOR_GREEN="\033[0;32m"
COLOR_OFF="\033[0m"
usage() {
cat 1>&2 <<EOF
Usage ${0##*/} [-h|?] [-p PATH] [-i INSTALL_DIR]
-p BUILD_DIR (optional): Path to the base dir for katran
-i INSTALL_DIR (optional): Install prefix path
-h|? Show this help message
EOF
}
while getopts ":hp:i:m" arg; do
case $arg in
p)
BUILD_DIR="${OPTARG}"
;;
i)
INSTALL_DIR="${OPTARG}"
;;
h | *) # Display help.
usage
exit 0
;;
esac
done
# Validate required parameters
if [ -z "${BUILD_DIR-}" ] ; then
echo -e "${COLOR_RED}[ INFO ] Build dir is not set. So going to build into _build ${COLOR_OFF}"
BUILD_DIR=${ROOT_DIR}/_build
mkdir -p "$BUILD_DIR"
fi
cd "$BUILD_DIR" || exit
DEPS_DIR=$BUILD_DIR/deps
mkdir -p "$DEPS_DIR" || exit
if [ -z "${INSTALL_DIR-}" ] ; then
echo -e "${COLOR_RED}[ INFO ] Install dir is not set. So going to install into ${DEPS_DIR} ${COLOR_OFF}"
INSTALL_DIR=${DEPS_DIR}
mkdir -p "$INSTALL_DIR"
fi
if [ -n "$FORCE_INSTALL" ]; then
rm -rf ./deps
rm -rf "$BUILD_DIR"
fi
if [ -n "$BUILD_EXAMPLE_THRIFT" ]; then
BUILD_EXAMPLE_THRIFT=1
export CMAKE_BUILD_EXAMPLE_THRIFT="$BUILD_EXAMPLE_THRIFT"
fi
if [ -z "$BUILD_EXAMPLE_GRPC" ]; then
BUILD_EXAMPLE_GRPC=1
export CMAKE_BUILD_EXAMPLE_GRPC="$BUILD_EXAMPLE_GRPC"
fi
if [ -n "$BUILD_TOOLS" ]; then
BUILD_TOOLS=1
export CMAKE_BUILD_TOOLS="$BUILD_TOOLS"
fi
if [ -n "$BUILD_KATRAN_TPR" ]; then
BUILD_KATRAN_TPR=1
export CMAKE_BUILD_KATRAN_TPR="$BUILD_KATRAN_TPR"
fi
get_dev_tools() {
if [ -f /etc/redhat-release ]; then
sudo yum install -y epel-release
sudo yum-config-manager --enable PowerTools
sudo yum groupinstall -y "Development Tools"
sudo yum install -y cmake
else
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
libbison-dev \
bison \
flex \
bc \
libbpfcc-dev
fi
}
get_required_libs() {
if [ -f /etc/redhat-release ]; then
sudo yum install -y \
git \
elfutils-libelf-devel \
libmnl-devel \
xz-devel \
re2-devel \
libatomic-static \
libsodium-static \
fmt-devel
else
sudo apt-get install -y \
libgoogle-glog-dev \
libgflags-dev \
libelf-dev \
libmnl-dev \
liblzma-dev \
libre2-dev \
libsodium-dev \
libfmt-dev
fi
}
get_libevent() {
if [ ! -f /etc/redhat-release ]; then
# not needed on ubuntu as it is available as a package
return
fi
if [ -f "${DEPS_DIR}/libevent_installed" ]; then
return
fi
EVENT_DIR=$DEPS_DIR/event
EVENT_BUILD_DIR=$DEPS_DIR/event/_build
rm -rf "$EVENT_DIR"
pushd .
echo -e "${COLOR_GREEN}[ INFO ] Cloning libevent repo ${COLOR_OFF}"
git clone https://github.com/libevent/libevent --depth 1 --branch release-2.1.11-stable "$EVENT_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Building libevent ${COLOR_OFF}"
mkdir -p "$EVENT_BUILD_DIR"
cd "$EVENT_BUILD_DIR" || exit
cmake -DEVENT__DISABLE_SAMPLES=on -DEVENT__DISABLE_TESTS=on -DCXX_STD=gnu++17 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
..
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}Libevent is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/libevent_installed"
}
get_gflags() {
if [ ! -f /etc/redhat-release ]; then
# not needed on ubuntu as it is available as a package
return
fi
if [ -f "${DEPS_DIR}/gflags_installed" ]; then
return
fi
GFLAGS_DIR=$DEPS_DIR/gflags
GFLAGS_BUILD_DIR=$DEPS_DIR/gflags/_build
rm -rf "$GFLAGS_DIR"
pushd .
echo -e "${COLOR_GREEN}[ INFO ] Cloning gflags repo ${COLOR_OFF}"
git clone https://github.com/gflags/gflags --depth 1 --branch v2.2.2 "$GFLAGS_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Building gflags ${COLOR_OFF}"
mkdir -p "$GFLAGS_BUILD_DIR"
cd "$GFLAGS_BUILD_DIR" || exit
cmake -DCXX_STD=gnu++17 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
..
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}Gflags is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/gflags_installed"
}
get_folly() {
if [ -f "${DEPS_DIR}/folly_installed" ]; then
return
fi
FOLLY_DIR=$DEPS_DIR/folly
FOLLY_BUILD_DIR=$DEPS_DIR/folly/build
rm -rf "$FOLLY_DIR"
if [ -f /etc/redhat-release ]; then
sudo yum install -y \
boost-devel \
boost-static \
lz4-devel \
xz-devel \
snappy-devel \
zlib-devel \
zlib-static \
glog-devel \
python3-scons \
double-conversion-devel \
openssl-devel \
libdwarf-devel \
elfutils-devel elfutils-devel-static \
libunwind-devel \
bzip2-devel \
binutils-devel
else
sudo apt-get install -y \
g++ \
automake \
autoconf \
autoconf-archive \
libtool \
libboost-all-dev \
libevent-dev \
libdouble-conversion-dev \
libgoogle-glog-dev \
libgflags-dev \
liblz4-dev \
liblzma-dev \
libsnappy-dev \
make \
zlib1g-dev \
binutils-dev \
libjemalloc-dev \
libssl-dev \
pkg-config \
libiberty-dev \
libunwind8-dev \
libdwarf-dev
fi
pushd .
echo -e "${COLOR_GREEN}[ INFO ] Cloning folly repo ${COLOR_OFF}"
git clone https://github.com/facebook/folly --depth 1 "$FOLLY_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Building Folly ${COLOR_OFF}"
mkdir -p "$FOLLY_BUILD_DIR"
cd "$FOLLY_BUILD_DIR" || exit
cmake -DCXX_STD=gnu++17 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
..
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}Folly is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/folly_installed"
}
get_clang() {
if [ -f "${DEPS_DIR}/clang_installed" ]; then
return
fi
if [ -f /etc/redhat-release ]; then
sudo yum install -y clang llvm
else
CLANG_DIR=$DEPS_DIR/clang
rm -rf "$CLANG_DIR"
pushd .
mkdir -p "$CLANG_DIR"
cd "$CLANG_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Downloading Clang ${COLOR_OFF}"
# download platform appropriate version (9.0+) of clang from https://github.com/llvm/llvm-project/releases/
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
tar xvf ./clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
echo -e "${COLOR_GREEN}Clang is installed ${COLOR_OFF}"
popd
fi
touch "${DEPS_DIR}/clang_installed"
}
get_gtest() {
if [ -f "${DEPS_DIR}/googletest_installed" ]; then
return
fi
GTEST_DIR=${DEPS_DIR}/googletest
GTEST_BUILD_DIR=${DEPS_DIR}/googletest/build
rm -rf "$GTEST_DIR"
pushd .
mkdir -p "$GTEST_DIR"
cd "$GTEST_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Cloning googletest repo ${COLOR_OFF}"
git clone --depth 1 https://github.com/google/googletest
mkdir -p "$GTEST_BUILD_DIR"
cd "$GTEST_BUILD_DIR"
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
../googletest
make install
echo -e "${COLOR_GREEN}googletest is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/googletest_installed"
}
get_mstch() {
if [ -f "${DEPS_DIR}/mstch_installed" ]; then
return
fi
MSTCH_DIR=${DEPS_DIR}/mstch
MSTCH_BUILD_DIR=${DEPS_DIR}/mstch/build
rm -rf "${MSTCH_DIR}"
pushd .
cd "${DEPS_DIR}"
echo -e "${COLOR_GREEN}[ INFO ] Cloning mstch repo ${COLOR_OFF}"
git clone --depth 1 https://github.com/no1msd/mstch
mkdir -p "${MSTCH_BUILD_DIR}"
cd "${MSTCH_BUILD_DIR}" || exit
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
..
make -j "$NCPUS"
make install
popd
echo -e "${COLOR_GREEN}mstch is installed ${COLOR_OFF}"
touch "${DEPS_DIR}/mstch_installed"
}
get_fizz() {
if [ -f "${DEPS_DIR}/fizz_installed" ]; then
return
fi
FIZZ_DIR=$DEPS_DIR/fizz
FIZZ_BUILD_DIR=$DEPS_DIR/fizz/build/
rm -rf "${FIZZ_DIR}"
pushd .
echo -e "${COLOR_GREEN}[ INFO ] Cloning fizz repo ${COLOR_OFF}"
git clone https://github.com/facebookincubator/fizz "$FIZZ_DIR"
echo -e "${COLOR_GREEN}[ INFO ] install dependencies ${COLOR_OFF}"
echo -e "${COLOR_GREEN}Building Fizz ${COLOR_OFF}"
mkdir -p "$FIZZ_BUILD_DIR"
cd "$FIZZ_BUILD_DIR" || exit
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DBUILD_TESTS=OFF \
"$FIZZ_DIR/fizz"
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}Fizz is installed ${COLOR_OFF}"
popd
echo -e "${COLOR_GREEN}Fizz is installed ${COLOR_OFF}"
touch "${DEPS_DIR}/fizz_installed"
}
get_wangle() {
if [ -f "${DEPS_DIR}/wangle_installed" ]; then
return
fi
WANGLE_DIR=$DEPS_DIR/wangle
WANGLE_BUILD_DIR=$DEPS_DIR/wangle/build/
rm -rf "$WANGLE_DIR"
pushd .
cd "${DEPS_DIR}"
echo -e "${COLOR_GREEN}[ INFO ] Cloning wangle repo ${COLOR_OFF}"
git clone --depth 1 https://github.com/facebook/wangle "$WANGLE_DIR"
mkdir -p "$WANGLE_BUILD_DIR"
cd "$WANGLE_BUILD_DIR" || exit
echo -e "${COLOR_GREEN}Building Wangle ${COLOR_OFF}"
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
../wangle
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}wangle is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/wangle_installed"
}
get_zstd() {
if [ -f "${DEPS_DIR}/zstd_installed" ]; then
return
fi
ZSTD_DIR=$DEPS_DIR/zstd
rm -rf "$ZSTD_DIR"
pushd .
cd "$DEPS_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Cloning zstd repo ${COLOR_OFF}"
git clone --depth 1 https://github.com/facebook/zstd --branch v1.3.7
cd "$ZSTD_DIR"
make -j "$NCPUS"
sudo make install
echo -e "${COLOR_GREEN}zstd is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/zstd_installed"
}
get_fmt() {
if [ -f "$DEPS_DIR/fmt_installed" ]; then
return
fi
FMT_DIR=$DEPS_DIR/fmt
FMT_BUILD_DIR=$DEPS_DIR/fmt/build/
rm -rf "$FMT_DIR"
pushd .
cd "$DEPS_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Cloning fmt repo ${COLOR_OFF}"
git clone https://github.com/fmtlib/fmt
mkdir -p "$FMT_BUILD_DIR"
cd "$FMT_BUILD_DIR"
cmake -DCXX_STD=gnu++17 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
..
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}fmt is installed ${COLOR_OFF}"
popd
touch "$DEPS_DIR/fmt_installed"
}
get_fbthrift() {
if [ -f "$DEPS_DIR/fbthrift_installed" ]; then
return
fi
FBTHRIFT_DIR=$DEPS_DIR/fbthrift
FBTHRIFT_BUILD_DIR=$DEPS_DIR/fbthrift/build/
rm -rf "$FBTHRIFT_DIR"
# install fb thrift specific deps
sudo apt-get install -y \
libkrb5-dev \
flex
pushd .
cd "$DEPS_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Cloning fbthrift repo ${COLOR_OFF}"
git clone --depth 1 https://github.com/facebook/fbthrift || true
mkdir -p "$FBTHRIFT_BUILD_DIR"
cd "$FBTHRIFT_BUILD_DIR"
cmake -DCXX_STD=gnu++17 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
..
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}fbthrift is installed ${COLOR_OFF}"
popd
touch "$DEPS_DIR/fbthrift_installed"
}
get_rsocket() {
if [ -f "$DEPS_DIR/rsocket_installed" ]; then
return
fi
RSOCKET_DIR=$DEPS_DIR/rsocket-cpp
RSOCKET_BUILD_DIR=$DEPS_DIR/rsocket-cpp/build/
rm -rf "$RSOCKET_DIR"
pushd .
cd "$DEPS_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Cloning rsocket repo ${COLOR_OFF}"
git clone --depth 1 https://github.com/rsocket/rsocket-cpp || true
mkdir -p "$RSOCKET_BUILD_DIR"
cd "$RSOCKET_BUILD_DIR" || exit
cmake -DCXX_STD=gnu++17 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
..
make -j "$NCPUS"
make install
echo -e "${COLOR_GREEN}rsocket is installed ${COLOR_OFF}"
popd
touch "$DEPS_DIR/rsocket_installed"
}
get_grpc() {
if [ -f "${DEPS_DIR}/grpc_installed" ]; then
return
fi
GO_INSTALLED=$(which go || true)
if [ -z "$GO_INSTALLED" ]; then
if [ -f /etc/centos-release ]; then
sudo yum install -y golang
else
sudo apt-get install -y golang
fi
fi
GRPC_DIR=$DEPS_DIR/grpc
GRPC_BUILD_DIR=$DEPS_DIR/grpc/_build/
rm -rf "$GRPC_DIR"
pushd .
cd "$DEPS_DIR"
echo -e "${COLOR_GREEN}[ INFO ] Cloning grpc repo ${COLOR_OFF}"
# pin specific release of grpc to avoid build failures
# with new changes in grpc/absl
git clone --depth 1 https://github.com/grpc/grpc --branch v1.49.1
# this is to deal with a nested dir
cd grpc
git submodule update --init
mkdir -p "$GRPC_BUILD_DIR"
cd "$GRPC_BUILD_DIR" || exit
cmake -DCXX_STD=gnu++17 \
-DCMAKE_CXX_FLAGS=-Wno-unused-result \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \
-DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \
..
make -j "$NCPUS"
make install
cd "$GRPC_DIR"/third_party/protobuf
make && make install
echo -e "${COLOR_GREEN}grpc is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/grpc_installed"
}
get_libbpf() {
if [ -f "${DEPS_DIR}/libbpf_installed" ]; then
return
fi
LIBBPF_DIR="${DEPS_DIR}/libbpf"
rm -rf "${LIBBPF_DIR}"
pushd .
cd "${DEPS_DIR}"
echo -e "${COLOR_GREEN}[ INFO ] Cloning libbpf repo ${COLOR_OFF}"
git clone --depth 1 https://github.com/libbpf/libbpf || true
cd "${LIBBPF_DIR}"/src
make
#on centos the cp -fpR used was throwing an error, so just use a regular cp -R
if [ -f /etc/redhat-release ]; then
sed -i 's/cp -fpR/cp -R/g' Makefile
fi
DESTDIR="$INSTALL_DIR" make install
cd "$LIBBPF_DIR"
cp -r include/uapi "$INSTALL_DIR"/usr/include/bpf/
cd "$INSTALL_DIR"/usr/include/bpf
# override to use local bpf.h instead of system wide
sed -i 's/#include <linux\/bpf.h>/#include <bpf\/uapi\/linux\/bpf.h>/g' ./bpf.h
sed -i 's/#include <linux\/bpf.h>/#include <bpf\/uapi\/linux\/bpf.h>/g' ./libbpf.h
sed -i 's/#include <linux\/bpf.h>/#include <bpf\/uapi\/linux\/bpf.h>/g' ./libbpf_legacy.h
# Move to CMAKE_PREFIX_PATH so that cmake can easily discover them
cd "$INSTALL_DIR"
mv "$INSTALL_DIR"/usr/include/bpf "$INSTALL_DIR"/include/
cp -r "$INSTALL_DIR"/usr/lib64/* "$INSTALL_DIR"/lib/
echo -e "${COLOR_GREEN}libbpf is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/libbpf_installed"
}
get_bpftool() {
if [ -f "${DEPS_DIR}/bpftool_installed" ]; then
return
fi
BPFTOOL_DIR="${DEPS_DIR}/bpftool"
rm -rf "${BPFTOOL_DIR}"
pushd .
cd "${DEPS_DIR}"
echo -e "${COLOR_GREEN}[ INFO ] Cloning bpftool repo ${COLOR_OFF}"
git clone --recurse-submodules https://github.com/libbpf/bpftool.git || true
cd "${BPFTOOL_DIR}"/src
make
cp "${BPFTOOL_DIR}"/src/bpftool "${INSTALL_DIR}/bin/bpftool"
echo -e "${COLOR_GREEN}bpftool is installed ${COLOR_OFF}"
popd
touch "${DEPS_DIR}/bpftool_installed"
}
build_katran() {
pushd .
KATRAN_BUILD_DIR=$BUILD_DIR/build
rm -rf "$KATRAN_BUILD_DIR"
mkdir -p "$KATRAN_BUILD_DIR"
cd "$KATRAN_BUILD_DIR" || exit
LIB_BPF_PREFIX="$INSTALL_DIR"
cmake -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=ON \
-DLIB_BPF_PREFIX="$LIB_BPF_PREFIX" \
-DBUILD_TESTS=On \
../..
make -j "$NCPUS"
popd
"${ROOT_DIR}"/build_bpf_modules_opensource.sh \
-s "${ROOT_DIR}" \
-b "${BUILD_DIR}" \
2>/dev/null
}
test_katran() {
pushd .
cd "$BUILD_DIR"/build/katran/lib/tests/
ctest -v ./*
cd ../testing/
ctest -v ./*
popd
}
get_dev_tools
get_required_libs
get_libevent
get_fmt
get_gflags
get_folly
get_clang
get_gtest
get_libbpf
if [ "$BUILD_EXAMPLE_THRIFT" -eq 1 ]; then
get_mstch
get_fizz
get_wangle
get_zstd
get_rsocket
get_fbthrift
fi
if [ "$BUILD_EXAMPLE_GRPC" -eq 1 ]; then
get_grpc
fi
if [ "$BUILD_KATRAN_TPR" -eq 1 ]; then
get_bpftool
fi
if [ -z "$INSTALL_DEPS_ONLY" ]; then
build_katran
test_katran
fi