-
Notifications
You must be signed in to change notification settings - Fork 6
/
ruyi-build-dynamorio-inner
executable file
·89 lines (73 loc) · 2.32 KB
/
ruyi-build-dynamorio-inner
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
#!/bin/bash
set -e
ARCH="${1:-amd64}"
P="dynamorio-10.93.19979"
PV="10.93.19979"
RUYI_DATESTAMP=20240914
case "$ARCH" in
amd64|arm64|riscv64)
;;
*)
echo "invalid ARCH: choices are amd64 (default), arm64 or riscv64" >&2
exit 1
;;
esac
OUT_P="dynamorio-riscv-$PV-ruyi.$RUYI_DATESTAMP"
INSTALL_ROOT="/tmp/prefix/$OUT_P"
pushd /tmp
git clone --depth 1 --recurse-submodules -j4 https://github.com/DynamoRIO/dynamorio.git -b "cronbuild-${PV}"
popd
SRC_DIR="/tmp/dynamorio"
CONFIG_ARGS=(
-G Ninja
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX="$INSTALL_ROOT"
-DBUILD_TOOLS=ON
-DBUILD_SAMPLES=ON
-DBUILD_TESTS=OFF
-DTARGET_ARCH=riscv64
-DDISABLE_WARNINGS=ON # indeed -Werror has to be disabled
)
case "$ARCH" in
arm64)
CONFIG_ARGS+=(
-DCMAKE_TOOLCHAIN_FILE="$SRC_DIR/make/toolchain-aarch64.cmake"
-DCMAKE_FIND_ROOT_PATH=/sysroot/arm64
)
;;
riscv64)
CONFIG_ARGS+=(
-DCMAKE_TOOLCHAIN_FILE="$SRC_DIR/make/toolchain-riscv64.cmake"
-DCMAKE_FIND_ROOT_PATH=/sysroot/riscv64
# libsnappy and liblz4 is missing static libraries so the linker gets
# passed bare -lfoo flags, without sysroot
-DCMAKE_SYSROOT_LINK=/sysroot/riscv64
# XXX: force static linking of libpthread and libdl
# fails to build otherwise: errors about undefined e.g. _dl_stack_flags from inside nptl
# https://stackoverflow.com/questions/5738000/undefined-reference-error-dl-stack-flags-with-gcc-and-pthreads
-Dlibdl:FILEPATH=/sysroot/riscv64/usr/lib/riscv64-linux-gnu/libdl.so.2
-Dlibpthread:FILEPATH=/sysroot/riscv64/usr/lib/riscv64-linux-gnu/libpthread.so.0
)
;;
esac
# TODO: linking fails for now, turns out these are optional
rm /sysroot/riscv64/usr/lib/riscv64-linux-gnu/liblz4.*
rm /sysroot/riscv64/usr/lib/riscv64-linux-gnu/libsnappy.*
# have to patch the upstream-provided toolchain file to point to our complete
# sysroot
pushd "$SRC_DIR"/make
sed -i 's@CMAKE_FIND_ROOT_PATH "/usr/riscv64-\${TARGET_ABI}"@CMAKE_FIND_ROOT_PATH "/sysroot/riscv64"@' toolchain-riscv64.cmake
popd
mkdir /tmp/build
pushd /tmp/build
cmake "$SRC_DIR" "${CONFIG_ARGS[@]}"
ninja install
popd
pushd "$INSTALL_ROOT"
mv bin64 bin
ln -s bin bin64
popd
pushd "/tmp/prefix"
tar --zstd -cvf "/out/$OUT_P.$ARCH.tar.zst" \
"$OUT_P"
popd