forked from NetSys/NetBricks
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.sh
executable file
·350 lines (317 loc) · 9.78 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
#!/bin/bash
# Stop on any errors
set -e
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
BUILD_SCRIPT=$( basename "$0" )
if [[ -z ${CARGO_INCREMENTAL} ]] || [[ $CARGO_INCREMENTAL = false ]] || [[ $CARGO_INCREMENTAL = 0 ]]; then
export CARGO_INCREMENTAL="CARGO_INCREMENTAL=0 "
fi
if [[ -z ${RUST_BACKTRACE} ]] || [[ RUST_BACKTRACE = true ]] || [[ RUST_BACKTRACE = 1 ]]; then
export RUST_BACKTRACE="RUST_BACKTRACE=1 "
fi
echo "Current Cargo Incremental Setting: ${CARGO_INCREMENTAL}"
echo "Current Rust Backtrace Setting: ${RUST_BACKTRACE}"
# Display
C='\033[1;34m'
NC='\033[0m'
CARGO_LOC=`which cargo || true`
export CARGO=${CARGO_PATH-"${CARGO_LOC}"}
CLIPPY_ARGS="--all-targets --all-features -- -D clippy::wildcard_dependencies -D clippy::cargo_common_metadata -D warnings"
CLANG_FMT=`which clang-format || true`
DPDK_VER=18.11.2
DPDK_HOME="/opt/dpdk/dpdk-stable-${DPDK_VER}"
DPDK_LD_PATH="${DPDK_HOME}/build/lib"
DPDK_CONFIG_FILE=${DPDK_CONFIG_FILE-"${DPDK_HOME}/config/common_linuxapp"}
NATIVE_LIB_PATH="${BASE_DIR}/native"
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
source ${BASE_DIR}/examples.sh
if [[ "$OSTYPE" == "darwin"* ]]; then
proc=`sysctl -n hw.physicalcpu`
else
proc=`nproc`
fi
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
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} 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} clean || true
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/$example
${CARGO} clean || true
popd
done
make clean -C ${BASE_DIR}/native
rm -rf ${BASE_DIR}/target
}
build_fmwk () {
find_sctp
native
pushd $BASE_DIR/framework
${CARGO} build
popd
}
if [ $# -ge 1 ]; then
TASK=$1
else
TASK=build
fi
case $TASK in
build_native)
native
;;
build)
build_fmwk
for example in ${examples[@]}; do
if [ -f $BASE_DIR/$example/check.sh ]; then
pushd ${BASE_DIR}/${example}
${CARGO} build
popd
fi
done
;;
build_all)
build_fmwk
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} build
popd
done
;;
build_fmwk)
build_fmwk
;;
build_example)
shift
if [ $# -lt 1 ]; then
echo "Can build one of the following examples:"
for example in ${examples[@]}; do
base_eg=$( basename ${example} )
printf "\t %s\n" ${base_eg}
done
exit 0
fi
build_dir=$1
if [ ! -e ${BASE_DIR}/examples/${build_dir}/Cargo.toml ]; then
echo "No Cargo.toml, not valid"
fi
pushd ${BASE_DIR}/examples/${build_dir}
${CARGO} build
popd
;;
build_example_rel)
shift
if [ $# -lt 1 ]; then
echo "Can build a release for one of the following examples:"
for example in ${examples[@]}; do
base_eg=$( basename ${example} )
printf "\t %s\n" ${base_eg}
done
exit 0
fi
build_dir=$1
if [ ! -e ${BASE_DIR}/examples/${build_dir}/Cargo.toml ]; then
echo "No Cargo.toml, not valid"
fi
pushd ${BASE_DIR}/examples/${build_dir}
${CARGO} build --release
popd
;;
build_rel)
find_sctp
native
pushd $BASE_DIR/framework
${CARGO} build --release
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} build --release
popd
done
;;
check_examples)
python scripts/check-examples.py "${examples[@]}"
;;
check_manifest)
pushd ${BASE_DIR}
${CARGO} verify-project --verbose
popd
pushd ${BASE_DIR}/framework
${CARGO} verify-project | grep true
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} verify-project | grep true
popd
done
;;
clean)
clean
;;
cov)
build_fmwk
${CARGO} tarpaulin --root framework --out Xml
;;
debug)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${BASE_DIR}/target/debug/$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}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
rust-gdb --args $executable "$@"
;;
doc)
pushd $BASE_DIR/framework
${CARGO} rustdoc -- \
--no-defaults --passes "collapse-docs" --passes \
"unindent-comments"
popd
;;
env)
echo "export PATH=\"${BIN_DIR}:${PATH}\""
echo "export LD_LIBRARY_PATH=\"${NATIVE_LIB_PATH}:${TOOLS_BASE}:${LD_LIBRARY_PATH}\""
;;
fmt)
${CLANG_FMT} -i $NATIVE_LIB_PATH/*.c $NATIVE_LIB_PATH/include/*.h $NATIVE_LIB_PATH/test/*.c
pushd $BASE_DIR/framework
${CARGO} fmt
${CLANG_FMT} -i src/native_include/*.h
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} fmt
popd
done
;;
lint)
echo "Linting w/: $CLIPPY_ARGS"
${CARGO} clippy $CLIPPY_ARGS
;;
run)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${BASE_DIR}/target/debug/$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}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
$executable "$@"
;;
run_rel)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${BASE_DIR}/target/release/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build_rel
fi
export PATH="${BIN_DIR}:${PATH}"
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${LD_LIBRARY_PATH}"
sudo env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" LD_PRELOAD="$LD_PRELOAD" \
$executable "$@"
;;
sctp)
find_sctp
;;
test)
if [ $# -lt 2 ]; then
echo "We will build & run these tests:"
for testname in ${examples[@]}; do
if [ -f $BASE_DIR/$testname/check.sh ]; then
echo -e "${C}$testname${NC}"
fi
done
echo "...and all unit and property-based tests"
pushd $BASE_DIR/framework
export LD_LIBRARY_PATH="${NATIVE_LIB_PATH}:${DPDK_LD_PATH}:${LD_LIBRARY_PATH}"
${CARGO} test -- --nocapture
popd
for testname in ${examples[@]}; do
if [ -f $BASE_DIR/$testname/check.sh ]; then
pushd $BASE_DIR/$testname
echo -e "${C}RUNNING: $testname${NC}"
./check.sh
popd
fi
done
else
test=$2
echo -e "${C}RUNNING: $test${NC}"
pushd $BASE_DIR/examples/$test
./check.sh
popd
fi
;;
*)
cat <<endhelp
./build.sh <Command>
Where command is one of
build: Build the project (this includes framework and testable examples).
build_all: Build the project (this includes framework and all examples).
build_example: Build a particular example.
build_example_rel: Build a particular example in release mode.
build_fmwk: Just build NetBricks framework.
build_native: Build the DPDK C API.
build_rel: Build a release of the project (this includes framework and all examples).
clean: Remove all built files.
cov: Run test coverage.
debug: Debug one of the examples (Must specify example name and examples).
doc: Run rustdoc and produce documentation.
env: Environment variables, run as eval \`./build.sh env\`.
fmt: Format all files via rustfmt.
lint: Run clippy to lint all files.
run: Run one of the examples (Must specify example name and arguments).
run_rel: Run one of the examples in release mode (Must specify example name and arguments).
sctp: Check if sctp library is present.
test: Run a specific test or all tests.
endhelp
esac