-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·303 lines (272 loc) · 8.31 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
#!/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}"
CARGO_FLAGS="--target x86_64-fortanix-unknown-sgx"
MODE="x86_64-fortanix-unknown-sgx/"
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"
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
}
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
rm -rf ${BASE_DIR}/target
}
build_fmwk () {
pushd $BASE_DIR/framework
${CARGO} build $CARGO_FLAGS
popd
}
if [ $# -ge 1 ]; then
TASK=$1
else
TASK=build
fi
case $TASK in
build)
build_fmwk
for example in ${examples[@]}; do
if [ -f $BASE_DIR/$example/check.sh ]; then
pushd ${BASE_DIR}/${example}
${CARGO} build $CARGO_FLAGS
popd
fi
done
;;
build_all)
build_fmwk
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} build $CARGO_FLAGS
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 $CARGO_FLAGS
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 $CARGO_FLAGS
popd
;;
build_rel)
pushd $BASE_DIR/framework
${CARGO} build --release $CARGO_FLAGS
popd
for example in ${examples[@]}; do
pushd ${BASE_DIR}/${example}
${CARGO} build --release $CARGO_FLAGS
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
;;
debug)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${BASE_DIR}/target/${MODE}debug/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
sudo env PATH="$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}\""
;;
fmt)
pushd $BASE_DIR/framework
${CARGO} fmt
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/${MODE}debug/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build
fi
export PATH="${BIN_DIR}:${PATH}"
# echo "sudo env PATH=\"$PATH\" LD_PRELOAD=\"$LD_PRELOAD\" $executable \"$@\""
sudo env PATH="$PATH" LD_PRELOAD="$LD_PRELOAD" \
$executable "$@"
;;
run_rel)
shift
if [ $# -le 0 ]; then
print_examples
fi
cmd=$1
shift
executable=${BASE_DIR}/target/${MODE}release/$cmd
if [ ! -e ${executable} ]; then
echo "${executable} not found, building"
${BASE_DIR}/${BUILD_SCRIPT} build_rel
fi
export PATH="${BIN_DIR}:${PATH}"
sudo env PATH="$PATH" LD_PRELOAD="$LD_PRELOAD" \
$executable "$@"
;;
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 $testname
fi
done
echo "...and all unit and property-based tests"
pushd $BASE_DIR/framework
${CARGO} test $CARGO_FLAGS
popd
for testname in ${examples[@]}; do
if [ -f $BASE_DIR/$testname/check.sh ]; then
pushd $BASE_DIR/$testname
./check.sh
popd
fi
done
else
test=$2
echo "Running ${test}"
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
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