forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ndndpdk-depends.sh
executable file
·450 lines (414 loc) · 12.1 KB
/
ndndpdk-depends.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
#!/bin/bash
set -euo pipefail
NEEDED_BINARIES=(
curl
gpg
jq
lsb_release
)
MISSING_BINARIES=()
SUDO=
SUDOPKG=
APTINSTALL='apt install --no-install-recommends'
if [[ -z ${SKIPROOTCHECK:-} ]]; then
NEEDED_BINARIES+=(sudo)
SUDO=sudo
SUDOPKG=sudo
APTINSTALL="sudo $APTINSTALL"
if [[ $(id -u) -eq 0 ]]; then
echo 'Do not run this script as root'
echo 'To skip this check, set the environment variable SKIPROOTCHECK=1'
exit 1
fi
fi
for B in "${NEEDED_BINARIES[@]}"; do
if ! command -v "$B" >/dev/null; then
MISSING_BINARIES+=("$B")
fi
done
if [[ ${#MISSING_BINARIES[@]} -gt 0 ]]; then
echo "Missing commands (${MISSING_BINARIES[*]}) to start this script. To install, run:"
echo " ${APTINSTALL} ca-certificates curl gpg jq lsb-release ${SUDOPKG}"
exit 1
fi
DFLT_CODEROOT=$HOME/code
DFLT_NODEVER=20
DFLT_GOVER=latest
DFLT_UBPFVER=a3e69808888b0f48e3a7972dd94115e46dad1e74
DFLT_LIBBPFVER=v1.4.6
DFLT_XDPTOOLSVER=v1.4.3
DFLT_URINGVER=liburing-2.7
DFLT_DPDKVER=v24.07
DFLT_DPDKPATCH=
DFLT_DPDKOPTS={}
DFLT_SPDKVER=v24.09
DFLT_NJOBS=$(nproc)
DFLT_TARGETARCH=native
HELP=0
CONFIRM=0
CODEROOT=$DFLT_CODEROOT
NODEVER=$DFLT_NODEVER
GOVER=$DFLT_GOVER
UBPFVER=$DFLT_UBPFVER
LIBBPFVER=$DFLT_LIBBPFVER
XDPTOOLSVER=$DFLT_XDPTOOLSVER
URINGVER=$DFLT_URINGVER
DPDKVER=$DFLT_DPDKVER
DPDKPATCH=$DFLT_DPDKPATCH
DPDKOPTS=$DFLT_DPDKOPTS
SPDKVER=$DFLT_SPDKVER
NJOBS=$DFLT_NJOBS
TARGETARCH=$DFLT_TARGETARCH
ARGS=$(getopt -o 'hy' -l 'dir:,node:,go:,ubpf:,libbpf:,xdp:,dpdk:,dpdk-patch:,dpdk-opts:,spdk:,uring:,jobs:,arch:' -- "$@")
eval set -- "$ARGS"
while true; do
case $1 in
-h)
HELP=1
shift
;;
-y)
CONFIRM=1
shift
;;
--dir)
CODEROOT=$2
shift 2
;;
--node)
NODEVER=$2
shift 2
;;
--go)
GOVER=$2
shift 2
;;
--ubpf)
UBPFVER=$2
shift 2
;;
--libbpf)
LIBBPFVER=$2
shift 2
;;
--xdp)
XDPTOOLSVER=$2
shift 2
;;
--uring)
URINGVER=$2
shift 2
;;
--dpdk)
DPDKVER=$2
DPDKPATCH=''
shift 2
;;
--dpdk-patch)
DPDKPATCH=$2
shift 2
;;
--dpdk-opts)
DPDKOPTS=$2
shift 2
;;
--spdk)
SPDKVER=$2
shift 2
;;
--jobs)
NJOBS=$2
shift 2
;;
--arch)
TARGETARCH=$2
shift 2
;;
--)
shift
break
;;
*) exit 1 ;;
esac
done
if [[ $HELP -eq 1 ]]; then
cat <<EOT
ndndpdk-depends.sh [OPTION]...
-h Display help and exit.
-y Skip confirmation.
--dir=${DFLT_CODEROOT}
Set where to download and compile the code.
--node=${DFLT_NODEVER}
Set Node.js major version. '0' to skip.
--go=${DFLT_GOVER}
Set Go version. 'latest' for the latest 1.x version. '0' to skip.
--ubpf=${DFLT_UBPFVER}
Set uBPF branch or commit SHA. '0' to skip.
--libbpf=${DFLT_LIBBPFVER}
Set libbpf branch or commit SHA. '0' to skip.
--xdp=${DFLT_XDPTOOLSVER}
Set xdp-tools branch or commit SHA. '0' to skip.
--uring=${DFLT_URINGVER}
Set liburing version. '0' to skip.
--dpdk=${DFLT_DPDKVER}
Set DPDK version. '0' to skip.
--dpdk-patch=${DFLT_DPDKPATCH}
Add DPDK patch series (comma separated). '0' to skip.
--dpdk-opts=${DFLT_DPDKOPTS}
Set/override DPDK Meson options (JSON object).
--spdk=${DFLT_SPDKVER}
Set SPDK version. '0' to skip.
--jobs=${DFLT_NJOBS}
Set number of parallel jobs.
--arch=${DFLT_TARGETARCH}
Set target architecture.
EOT
exit 0
fi
: "${NDNDPDK_DL_GITHUB:=https://github.com}"
: "${NDNDPDK_DL_NODESOURCE_DEB:=https://deb.nodesource.com}"
: "${NDNDPDK_DL_GODEV:=https://go.dev}"
: "${NDNDPDK_DL_DPDK_PATCHES:=https://patches.dpdk.org}"
# you can also set the GOPROXY environment variable, which will be persisted
curl_test() {
local SITE=${!1}
if ! curl -fsILS "$SITE${2:-}" >/dev/null; then
echo "Cannot reach ${SITE}"
echo "You can specify a mirror site by setting the $1 environment variable"
echo "Example: $1=${SITE}"
exit 1
fi
}
curl_test NDNDPDK_DL_GITHUB /robots.txt
curl_test NDNDPDK_DL_NODESOURCE_DEB
curl_test NDNDPDK_DL_GODEV /VERSION
curl_test NDNDPDK_DL_DPDK_PATCHES
github_download() {
local REPO=$1
local VER=$2
local DIR="${REPO#*/}-${VER#v}"
cd "$CODEROOT"
rm -rf "$DIR"
curl -fsLS "${NDNDPDK_DL_GITHUB}/${REPO}/archive/${VER}.tar.gz" | tar -xz
readlink -f "$DIR"
}
set_alternative() {
$SUDO update-alternatives --remove-all $1 || true
$SUDO update-alternatives --install /usr/bin/$1 $1 $2 1
}
APT_PKGS=(
clang-15
clang-format-15
cmake
doxygen
file
g++-12
gcc-12
git
lcov
libaio-dev
libc6-dev-i386
libelf-dev
libnuma-dev
libpcap-dev
libssl-dev
liburcu-dev
llvm-15
m4
make
ninja-build
patchelf
pkg-config
python-is-python3
python3-pip
python3-pyelftools
uuid-dev
yamllint
)
DISTRO=$(lsb_release -sc)
case $DISTRO in
jammy) ;;
bookworm)
APT_PKGS+=(meson)
;;
*)
echo "Distro ${DISTRO} is not supported by this script."
if [[ -z ${SKIPDISTROCHECK:-} ]]; then
echo 'To skip this check, set the environment variable SKIPDISTROCHECK=1'
exit 1
fi
;;
esac
if [[ $(uname -r | awk -F. '{ print ($1*1000+$2>=5014) }') -ne 1 ]] &&
[[ -z ${SKIPKERNELCHECK:-} ]]; then
echo 'Linux kernel 5.15 or newer is required'
echo 'To skip this check, set the environment variable SKIPKERNELCHECK=1'
exit 1
fi
echo "Will download to ${CODEROOT}"
echo 'Will install C compiler and build tools'
if [[ $NODEVER != 0 ]]; then
echo "Will install Node ${NODEVER}.x"
elif ! command -v corepack >/dev/null; then
echo '--node=0 specified but the `corepack` command was not found, which may cause build errors'
fi
if [[ $GOVER != 0 ]]; then
if [[ $GOVER == latest ]]; then
GOVER=$(curl -fsLS "${NDNDPDK_DL_GODEV}/VERSION?m=text" | head -1)
fi
echo "Will install Go ${GOVER}"
elif ! command -v go >/dev/null; then
echo '--go=0 specified but the `go` command was not found, which may cause build errors'
fi
echo 'Will install Go linters and tools'
if [[ $UBPFVER != 0 ]]; then
echo "Will install uBPF ${UBPFVER}"
elif ! [[ -f /usr/local/include/ubpf.h ]]; then
echo '--ubpf=0 specified but uBPF was not found, which may cause build errors'
fi
if [[ $LIBBPFVER != 0 ]]; then
echo "Will install libbpf ${LIBBPFVER}"
fi
if [[ $XDPTOOLSVER != 0 ]]; then
echo "Will install libxdp ${XDPTOOLSVER}"
fi
if [[ $URINGVER != 0 ]]; then
echo "Will install liburing ${URINGVER}"
elif ! pkg-config liburing; then
echo '--uring=0 specified but liburing was not found, which may cause build errors'
fi
if [[ $DPDKVER != 0 ]]; then
echo "Will install DPDK ${DPDKVER} for ${TARGETARCH} architecture"
echo -n "$DPDKPATCH" | xargs -d, --no-run-if-empty -I{} echo "Will patch DPDK with ${NDNDPDK_DL_DPDK_PATCHES}/series/{}/mbox/"
elif ! pkg-config libdpdk; then
echo '--dpdk=0 specified but DPDK was not found, which may cause build errors'
fi
if [[ $SPDKVER != 0 ]]; then
echo "Will install SPDK ${SPDKVER} for ${TARGETARCH} architecture"
elif ! pkg-config spdk_thread; then
echo '--spdk=0 specified but SPDK was not found, which may cause build errors'
fi
echo "Will compile with ${NJOBS} parallel jobs"
echo 'Will delete conflicting versions if present'
if [[ $CONFIRM -ne 1 ]]; then
read -p 'Press ENTER to continue or CTRL+C to abort '
fi
$SUDO mkdir -p "$CODEROOT"
$SUDO chown -R "$(id -u):$(id -g)" "$CODEROOT"
echo 'Dpkg::Options {
"--force-confdef";
"--force-confold";
}
APT::Install-Recommends "no";
APT::Install-Suggests "no";' | $SUDO tee /etc/apt/apt.conf.d/80custom >/dev/null
if [[ $NODEVER != 0 ]]; then
if ! [[ -f /etc/apt/keyrings/nodesource.gpg ]]; then
curl -fsLS ${NDNDPDK_DL_NODESOURCE_DEB}/gpgkey/nodesource-repo.gpg.key | $SUDO gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
fi
if ! [[ -f /etc/apt/sources.list.d/nodesource.list ]]; then
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] ${NDNDPDK_DL_NODESOURCE_DEB}/node_$NODEVER.x nodistro main" |
$SUDO tee /etc/apt/sources.list.d/nodesource.list
fi
APT_PKGS+=(nodejs)
fi
$SUDO apt-get -qq update
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get -qq dist-upgrade
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get -qq install "${APT_PKGS[@]}"
set_alternative gcc /usr/bin/gcc-12
set_alternative cc /usr/bin/gcc
set_alternative g++ /usr/bin/g++-12
set_alternative c++ /usr/bin/g++
set_alternative gcov /usr/bin/gcov-12
if ! [[ -d /usr/include/asm ]]; then
$SUDO ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm
fi
if ! command -v meson >/dev/null; then
cd "$(github_download mesonbuild/meson 1.2.1)"
./packaging/create_zipapp.py --outfile meson.pyz .
$SUDO install -m0755 meson.pyz /usr/local/bin/meson
fi
if [[ $GOVER != 0 ]]; then
$SUDO rm -rf /usr/local/go
curl -fsLS "${NDNDPDK_DL_GODEV}/dl/${GOVER}.linux-amd64.tar.gz" | $SUDO tar -C /usr/local -xz
if ! grep -q go/bin ~/.bashrc; then
echo 'export PATH=${HOME}/go/bin${PATH:+:}${PATH}' >>~/.bashrc
fi
if [[ -n ${GOPROXY:-} ]]; then
go env -w GOPROXY="$GOPROXY"
fi
set_alternative go /usr/local/go/bin/go
set_alternative gofmt /usr/local/go/bin/gofmt
fi
if [[ $UBPFVER != 0 ]]; then
cd "$(github_download iovisor/ubpf $UBPFVER)"
cmake -G Ninja -B build -D BUILD_SHARED_LIBS=1 -D UBPF_ENABLE_INSTALL=1
cmake --build build
$SUDO cmake --build build -t install
$SUDO rm -f /usr/local/lib/libubpf.a
fi
if [[ $LIBBPFVER != 0 ]]; then
cd "$(github_download libbpf/libbpf $LIBBPFVER)/src"
sh -c "umask 0000 && make -j${NJOBS}"
$SUDO find /usr/local/lib -name 'libbpf.*' -delete
$SUDO sh -c "umask 0000 && make install PREFIX=/usr/local LIBDIR=/usr/local/lib"
$SUDO install -d -m0755 /usr/local/include/linux
$SUDO install -m0644 ../include/uapi/linux/* /usr/local/include/linux
$SUDO ldconfig
fi
if [[ $XDPTOOLSVER != 0 ]]; then
cd "$(github_download xdp-project/xdp-tools $XDPTOOLSVER)"
CLANG=clang-15 LLC=llc-15 ./configure
sh -c "umask 0000 && make -j${NJOBS}"
$SUDO find /usr/local/lib '(' -name 'libxdp.*' -or -name 'xdp*.o' ')' -delete
$SUDO sh -c "umask 0000 && make install PREFIX=/usr/local LIBDIR=/usr/local/lib"
$SUDO ldconfig
fi
if [[ $URINGVER != 0 ]]; then
cd "$(github_download axboe/liburing $URINGVER)"
./configure --prefix=/usr/local
make -C src -j${NJOBS}
$SUDO find /usr/local/lib -name 'liburing.*' -delete
$SUDO find /usr/local/share/man -name 'io_uring*' -delete
$SUDO rm -rf /usr/local/include/liburing /usr/local/include/liburing.h
$SUDO make install
$SUDO ldconfig
fi
if [[ $DPDKVER != 0 ]]; then
cd "$(github_download DPDK/dpdk $DPDKVER)"
echo -n "$DPDKPATCH" | xargs -d, --no-run-if-empty -I{} \
sh -c "curl -fsLS ${NDNDPDK_DL_DPDK_PATCHES}/series/{}/mbox/ | patch -p1"
meson setup \
$(echo "$DPDKOPTS" | jq -r --arg arch "$TARGETARCH" '
{ debug:true, cpu_instruction_set:$arch, optimization:3, tests:false, disable_apps:"*" } + .
| to_entries[] | "-D"+.key+"="+(.value|tostring)
') --libdir=lib build
meson compile -C build -j ${NJOBS}
$SUDO find /usr/local/lib -name 'librte_*' -delete
$SUDO $(command -v meson) install -C build
$SUDO find /usr/local/lib -name 'librte_*.a' -delete
$SUDO ldconfig
fi
if [[ $SPDKVER != 0 ]]; then
cd "$(github_download spdk/spdk $SPDKVER)"
sed -i '/^\s*if .*isa-l\/autogen.sh/,/^\s*fi$/ s/.*/CONFIG[ISAL]=n/' configure
./configure --target-arch=${TARGETARCH} --with-shared \
--disable-tests --disable-unit-tests --disable-examples --disable-apps \
--with-dpdk --with-uring --without-uring-zns \
--without-idxd --without-crypto --without-fio --without-xnvme --without-vhost \
--without-virtio --without-vfio-user --without-rbd \
--without-rdma --without-fc --without-daos --without-iscsi-initiator --without-vtune \
--without-ocf --without-fuse --without-nvme-cuse --without-raid5f --without-wpdk \
--without-usdt --without-sma
make -j${NJOBS}
$SUDO find /usr/local/lib -name 'libspdk_*' -delete
$SUDO make install
$SUDO find /usr/local/lib -name 'libspdk_*.a' -delete
$SUDO ldconfig
fi
(
cd /tmp
go install golang.org/x/tools/cmd/godoc@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install mvdan.cc/sh/v3/cmd/shfmt@latest
)
echo "NDN-DPDK dependencies installation completed"