forked from NetSys/NetBricks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·726 lines (674 loc) · 22.3 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
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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
#!/bin/bash
# Authors:
# Autojit Panda
# Shuwen Sun
# Stop on any errors
set -e
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
BUILD_SCRIPT=$( basename "$0" )
EXT_BASE="$BASE_DIR/3rdparty"
TOOLS_BASE="$BASE_DIR/3rdparty/tools"
DOWNLOAD_DIR="${BASE_DIR}/3rdparty/downloads"
SCRIPTS_DIR="${EXT_BASE}/scripts"
BIN_DIR="${TOOLS_BASE}/bin"
if [ ! -e $DOWNLOAD_DIR ]; then
mkdir -p ${DOWNLOAD_DIR}
fi
if [ ! -e ${TOOLS_BASE} ]; then
mkdir -p ${TOOLS_BASE}
fi
TARGET_DIR="/home/jethros/data/cargo-target/release"
# setup the DPDK version
DPDK_VER=17.08
DPDK_HOME="${BASE_DIR}/3rdparty/dpdk"
DPDK_LD_PATH="${DPDK_HOME}/build/lib"
DPDK_CONFIG_FILE=${DPDK_CONFIG_FILE-"${EXT_BASE}/dpdk-confs/common_linuxapp-${DPDK_VER}"}
if grep "CONFIG_RTE_BUILD_SHARED_LIB=y" ${DPDK_CONFIG_FILE}; then
DPDK="${DPDK_HOME}/build/lib/libdpdk.so"
else
DPDK="${DPDK_HOME}/build/lib/libdpdk.a"
fi
CARGO_PATH="$HOME/.cargo/bin/cargo"
CARGO_LOC=$(which cargo || true)
export CARGO=${CARGO_PATH-"${CARGO_LOC}"}
if [ -z "${CARGO}" ] || [ ! -e "${CARGO}" ]; then
echo "Could not find a preinstalled Cargo in PATH. Set CARGO_PATH if necessary."
exit 1
fi
echo "Using Cargo from ${CARGO}"
# We fix the Cargo toolchain
declare toolchain=nightly-2022-08-15-x86_64-unknown-linux-gnu
MUSL_DOWNLOAD_PATH="${DOWNLOAD_DIR}/musl.tar.gz"
MUSL_RESULT="${EXT_BASE}/musl"
MUSL_TEST="${TOOLS_BASE}/lib/libc.a"
RUST_TEST="${TOOLS_BASE}/bin/rustc"
RUST_DOWNLOAD_PATH="${EXT_BASE}/rust"
LLVM_DOWNLOAD_PATH="${DOWNLOAD_DIR}/llvm.tar.gz"
LLVM_RESULT="${EXT_BASE}/llvm"
UNWIND_RESULT="${TOOLS_BASE}/lib/libunwind.a"
NATIVE_LIB_PATH="${BASE_DIR}/native"
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
source ${BASE_DIR}/examples.sh
REQUIRE_RUSTFMT=0
export RUSTFLAGS="-C target-cpu=native"
# RUST BACK_TRACE can be 1 or full
TRACING_LEVEL=1
rust_build_static() {
if [ ! -d "${RUST_DOWNLOAD_PATH}" ]; then
git clone https://github.com/rust-lang/rust.git \
${RUST_DOWNLOAD_PATH}
else
pushd ${RUST_DOWNLOAD_PATH}
git pull
popd
fi
pushd ${RUST_DOWNLOAD_PATH}
./configure --target=x86_64-unknown-linux-musl \
--musl-root=${TOOLS_BASE} --prefix=${TOOLS_BASE} \
--enable-optimize --disable-valgrind \
--disable-docs
popd
make -j -C ${RUST_DOWNLOAD_PATH}
make -j -C ${RUST_DOWNLOAD_PATH} install
}
rust_static() {
echo "Running rust_static"
if [ ! -e ${MUSL_TEST} ] || [ ! -z ${_BUILD_UPDATE_} ]; then
musl
else
echo "Musl found, not building"
fi
if [ ! -e ${UNWIND_RESULT} ] || [ ! -z ${_BUILD_UPDATE_} ]; then
libunwind
else
echo "libunwind found, not building"
fi
if [ ! -e ${RUST_TEST} ] || [ ! -z ${_BUILD_UPDATE_} ]; then
rust_build_static
else
echo "Rust found not building"
fi
export RUSTC="${TOOLS_BASE}/bin/rustc"
}
rust () {
echo "Building rust"
if [ ! -z ${RUST_STATIC} ]; then
rust_static
fi
if [ ! -d ${BIN_DIR} ]; then
mkdir -p ${BIN_DIR}
fi
cp ${SCRIPTS_DIR}/rust*.sh ${BIN_DIR}/
}
toggle_symbols () {
if [ ! -z ${NETBRICKS_SYMBOLS} ]; then
find ${BASE_DIR}/test -name Cargo.toml -exec sed -i 's/debug = false/debug = true/g' {} \;
else
find ${BASE_DIR}/test -name Cargo.toml -exec sed -i 's/debug = true/debug = false/g' {} \;
fi
}
find_sctp () {
set +o errexit
gcc -lsctp 2>&1 | grep "cannot find" >/dev/null
export SCTP_PRESENT=$?
set -o errexit
if [ ${SCTP_PRESENT} -eq 1 ]; then
echo "SCTP library found"
else
echo "No SCTP library found, install libsctp ('sudo apt-get install libsctp-dev' on debian)"
fi
}
native () {
make -j $proc -C $BASE_DIR/native
make -C $BASE_DIR/native install
}
print_examples () {
echo "The following examples are available:"
for eg in ${examples[@]}; do
if [ -e ${BASE_DIR}/${eg}/Cargo.toml ]; then
target=$( ${CARGO} +"$toolchain" read-manifest --manifest-path ${BASE_DIR}/${eg}/Cargo.toml | ${BASE_DIR}/scripts/read-target.py - )
printf "\t %s\n" ${target}
fi
done
exit 0
}
clean () {
pushd $BASE_DIR/framework
${CARGO} +"$toolchain" clean || true
popd
pushd $BASE_DIR/test/framework-test
${CARGO} +"$toolchain" clean || true
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/$example
${CARGO} +"$toolchain" clean || true
popd
done
make clean -C ${BASE_DIR}/native
rm -rf ${BASE_DIR}/target
}
UNWIND_BUILD="${TOOLS_BASE}"/libunwind
deps () {
# Build DPDK
export DPDK_CONFIG_FILE=${DPDK_CONFIG_FILE}
export DPDK_VER=${DPDK_VER}
if [ ! -e $DPDK ]; then
dpdk
else
echo "DPDK found not building"
fi
rust
if [ ${REQUIRE_RUSTFMT} -ne 0 ]; then
rust_fmt
fi
echo "Done with deps"
}
clean_deps() {
echo "Cleaning dependencies"
rm -rf ${BIN_DIR} || true
rm -rf ${DOWNLOAD_DIR} || true
rm -rf ${TOOLS_BASE} || true
rm -rf ${LLVM_RESULT} || true
rm -rf ${MUSL_RESULT} || true
rm -rf ${DPDK_HOME} || true
echo "Cleaned DEPS"
}
dpdk () {
$BASE_DIR/3rdparty/get-dpdk.sh ${DOWNLOAD_DIR}
proc="$(nproc)"
}
musl () {
curl http://www.musl-libc.org/releases/musl-1.1.10.tar.gz \
-o "${MUSL_DOWNLOAD_PATH}"
mkdir -p ${MUSL_RESULT}
tar zxvf "${MUSL_DOWNLOAD_PATH}" \
-C "${MUSL_RESULT}" --strip-components=1
pushd ${MUSL_RESULT}
./configure --disable-shared --prefix="$TOOLS_BASE"
make -j
make install
popd
}
libunwind () {
curl -L http://llvm.org/releases/3.7.0/llvm-3.7.0.src.tar.xz \
-o "${LLVM_DOWNLOAD_PATH}"
mkdir -p ${LLVM_RESULT}
tar xf "${LLVM_DOWNLOAD_PATH}" \
-C "${LLVM_RESULT}" --strip-components=1
UNWIND_DOWNLOAD="${DOWNLOAD_DIR}"/unwind.tar.gz
UNWIND_DIR="${LLVM_RESULT}/projects/libunwind"
mkdir -p ${UNWIND_DIR}
curl -L http://llvm.org/releases/3.7.0/libunwind-3.7.0.src.tar.xz \
-o "${UNWIND_DOWNLOAD}"
tar xf "${UNWIND_DOWNLOAD}" -C "${UNWIND_DIR}" --strip-components=1
mkdir -p "${UNWIND_BUILD}"
pushd ${UNWIND_BUILD}
cmake -DLLVM_PATH="${LLVM_RESULT}" -DLIBUNWIND_ENABLE_SHARED=0 \
"${UNWIND_DIR}"
make -j
mkdir -p ${TOOLS_BASE}/lib
cp lib/libunwind.a ${TOOLS_BASE}/lib
popd
}
rust_fmt () {
RUSTFMT=${BIN_DIR}/cargo-fmt
echo "Checking if ${RUSTFMT} exists (${REQUIRE_RUSTFMT})"
if [ ! -e "${RUSTFMT}" ]; then
${CARGO} +"$toolchain" install --root ${TOOLS_BASE} rustfmt
export RUSTFMT=${RUSTFMT}
else
export RUSTFMT=${RUSTFMT}
fi
}
if [ $# -ge 1 ]; then
TASK=$1
else
TASK=build
fi
case $TASK in
deps)
REQUIRE_RUSTFMT=1
deps
;;
enable_symbols)
export NETBRICKS_SYMBOLS=1
toggle_symbols
;;
disable_symbols)
unset NETBRICKS_SYMBOLS || true
toggle_symbols
;;
sctp)
find_sctp
;;
build_test)
shift
if [ $# -lt 1 ]; then
echo Can build one of the following tests:
for example in ${examples[@]}; do
base_eg=$( basename ${example} )
printf "\t %s\n" ${base_eg}
done
exit 1
fi
build_dir=$1
if [ ! -e ${BASE_DIR}/test/${build_dir}/Cargo.toml ]; then
echo "No Cargo.toml, not valid"
fi
pushd ${BASE_DIR}/test/${build_dir}
${CARGO} +"$toolchain" build --release
popd
;;
build_fmwk)
deps
native
find_sctp
pushd $BASE_DIR/framework
if [ ${SCTP_PRESENT} -eq 1 ]; then
${CARGO} +"$toolchain" build --release --features "sctp"
else
${CARGO} +"$toolchain" build --release
fi
popd
;;
build)
deps
native
find_sctp
pushd $BASE_DIR/framework
if [ ${SCTP_PRESENT} -eq 1 ]; then
${CARGO} +"$toolchain" build --release --features "sctp"
else
${CARGO} +"$toolchain" build --release
fi
popd
for example in ${examples[@]}; do
if [[ ${example} == *sctp* ]]; then
if [ ${SCTP_PRESENT} -eq 1 ]; then
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" build --release
popd
fi
else
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" build --release
popd
fi
done
;;
clippy)
deps
native
find_sctp
pushd $BASE_DIR/framework
if [ ${SCTP_PRESENT} -eq 1 ]; then
${CARGO} +"$toolchain" clippy --release --features "sctp"
else
${CARGO} +"$toolchain" clippy --release
fi
popd
for example in ${examples[@]}; do
if [[ ${example} == *sctp* ]]; then
if [ ${SCTP_PRESENT} -eq 1 ]; then
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" clippy --release
popd
fi
else
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" clippy --release
popd
fi
done
;;
miri)
deps
native
find_sctp
pushd $BASE_DIR/framework
if [ ${SCTP_PRESENT} -eq 1 ]; then
${CARGO} +"$toolchain" miri test --features "sctp"
else
${CARGO} +"$toolchain" miri test
fi
popd
for example in ${examples[@]}; do
if [[ ${example} == *sctp* ]]; then
if [ ${SCTP_PRESENT} -eq 1 ]; then
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" miri test
popd
fi
else
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" miri test
popd
fi
done
;;
ovs_create) # FIXME: create vswtch container????
clean
clean_deps
docker build -f container/Dockerfile -t jethrosun/netbricks-build:vswitch --build-arg dpdk_file="common_linuxapp-${DPDK_VER}.vswitch" ${BASE_DIR}
echo "Done building container as netbricks-build:vswitch"
docker push jethrosun/netbricks-build:vswitch
;;
ctr_update) # update the docker image
docker build --no-cache -f ${BASE_DIR}/build-container/Dockerfile -t jethrosun/netbricks-build:latest \
${BASE_DIR}/build-container
docker push jethrosun/netbricks-build:latest
;;
ctr_build) # build the container from the image
docker pull jethrosun/netbricks-build:latest
docker run -t -v /lib/modules:/lib/modules \
-v /usr/src:/usr/src -v ${BASE_DIR}:/opt/netbricks \
jethrosun/netbricks-build:latest /opt/netbricks/build.sh _build_container
;;
ctr_dpdk) # FIXME ???
shift
if [ $# -lt 1 ]; then
echo "build.sh ctr_dpdk dir"
exit 1
fi
result="$( readlink -f $1 )"
ctr="$( docker create netbricks:vswitch )"
docker cp ${ctr}:/opt/netbricks/3rdparty/dpdk $result
docker rm ${ctr}
;;
_build_container)
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y
export DPDK_CONFIG_FILE="${EXT_BASE}/dpdk-confs/common_linuxapp-${DPDK_VER}.container"
PATH="$HOME/.cargo/bin:$PATH" ${BASE_DIR}/build.sh build
;;
create_container) # DEPRECATED
clean
clean_deps
docker build -f container/Dockerfile -t netbricks:vswitch --build-arg dpdk_file="common_linuxapp-${DPDK_VER}.vswitch" ${BASE_DIR}
echo "Done building container as netbricks:vswitch"
;;
build_container_apanda) # DEPRECATED
docker pull apanda/netbricks-build:latest
docker run -t -v /lib/modules:/lib/modules \
-v /usr/src:/usr/src -v ${BASE_DIR}:/opt/netbricks \
apanda/netbricks-build:latest /opt/netbricks/build.sh _build_container
;;
update_container_apanda) # DEPRECATED
docker build --no-cache -f ${BASE_DIR}/build-container/Dockerfile -t apanda/netbricks-build:latest \
${BASE_DIR}/build-container
docker push apanda/netbricks-build:latest
;;
ctr_test_apanda) # DEPRECATED
docker pull apanda/netbricks-build:latest
docker run -t -v /lib/modules:/lib/modules \
-v /lib/modules/`uname -r`/build:/lib/modules/`uname -r`/build -v ${BASE_DIR}:/opt/netbricks \
-v /mnt/huge:/mnt/huge apanda/netbricks-build:latest /opt/netbricks/build.sh test
;;
test)
pushd $BASE_DIR/framework
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
${CARGO} +"$toolchain" test --release
popd
for testname in tcp_payload macswap; do
pushd $BASE_DIR/test/$testname
./check.sh
popd
done
;;
test-cov)
pushd $BASE_DIR/framework
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
${CARGO} +"$toolchain" tarpaulin -v
popd
;;
run)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
# executable=${BASE_DIR}/target/release/$cmd
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" RUST_LOG=info \
$executable "$@"
;;
profile)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
perf record --call-graph dwarf $executable "$@"
;;
run-trace)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
RUST_BACKTRACE=1 $executable "$@"
;;
run-full)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
RUST_BACKTRACE=full $executable "$@"
;;
gdb_debug)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
rust-gdb --args $executable "$@"
;;
lldb_debug)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
rust-lldb $executable "$@"
;;
track)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
heaptrack $executable "$@"
;;
valgrind)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${TARGET_DIR}/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}"
sudo valgrind --tool=massif env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" $executable "$@"
;;
update_rust)
_BUILD_UPDATE_=1
rust
cargo_clone
cargo_build
;;
fmt)
REQUIRE_RUSTFMT=1
deps
pushd $BASE_DIR/framework
${RUSTFMT} fmt -- --config-path ${BASE_DIR}/.travis || true
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${RUSTFMT} fmt -- --config-path ${BASE_DIR}/.travis || true
popd
done
;;
_fmt_travis)
echo "Running _fmt_travis"
pushd $BASE_DIR/framework
${CARGO} +"$toolchain" fmt -- --config-path ${BASE_DIR}/.travis --write-mode=diff
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" fmt -- --config-path ${BASE_DIR}/.travis --write-mode=diff
popd
done
;;
fmt_travis)
docker pull apanda/netbricks-build:latest
docker run -t -v /lib/modules:/lib/modules \
-v /lib/modules/`uname -r`/build:/lib/modules/`uname -r`/build -v ${BASE_DIR}:/opt/netbricks \
apanda/netbricks-build:latest /opt/netbricks/build.sh _fmt_travis
;;
check_manifest)
deps
pushd ${BASE_DIR}
${CARGO} +"$toolchain" verify-project --verbose
popd
pushd ${BASE_DIR}/framework
${CARGO} +"$toolchain" verify-project | grep true
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} +"$toolchain" verify-project | grep true
popd
done
;;
check_examples)
python3 scripts/check-examples.py "${examples[@]}"
;;
doc) # DEPRECATED
deps
pushd $BASE_DIR/framework
${CARGO} +"$toolchain" rustdoc -- \
--no-defaults --passes "collapse-docs" --passes \
"unindent-comments" --document-private-items \
-Z unstable-options --enable-index-page
popd
;;
lint)
deps
pushd $BASE_DIR/framework
${CARGO} +"$toolchain" clean
${CARGO} +"$toolchain" update # Clippy breaks with new compilers
${CARGO} +"$toolchain" build --features dev --verbose
popd
;;
dist_clean)
clean
clean_deps
;;
clean)
clean
;;
env)
echo "export PATH=\"${BIN_DIR}:${PATH}\""
echo "export LD_LIBRARY_PATH=\"${NATIVE_LIB_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}\""
;;
*)
cat <<endhelp
./build.sh <Command>
Where command is one of
deps: Build dependencies
sctp: Check if sctp library is present.
build_fmwk: Just build framework.
build_test: Build a particular test.
build: Build the project (this includes framework and all tests).
ovs_create: Build the Open vSwitch.
ctr_update: Update and push container used for build.
ctr_build: Build NetBricks within a container.
ctr_dpdk: Copy DPDK from container
create_container: Build the NetBricks container (DEPRECATED).
test: Run unit tests.
test-cov: Run cov tests.
run: Run one of the examples (Must specify example name and arguments).
profile: Run the network function with linux perf event for flamegraph.
trace: Run one of the network function with full trace.
gdb_debug: Debug one of the examples with GDB (Must specify example name and examples).
lldb_debug: Debug one of the examples with LLDB (Must specify example name and examples).
heaptrack: Run the network function with heaptrack for tracking memory usage.
valgrind: Run the network function with valgrind for tracking memory usage (broken).
update_rust: Pull and update Cargo.
fmt: Run rustfmt to format code.
fmt_travis: Run rustfmt to detect code formatting violations.
check_manifest: Check manifest.
check_examples: Check examples.
doc: Run rustdoc and produce documentation (DEPRECATED, it is handled in travis now).
lint: Run clippy to lint the project
dist_clean: Remove all support files
clean: Remove all built files
env: Environment variables, run as eval \`./build.sh env\`.
endhelp
;;
esac