]> git.ipfire.org Git - thirdparty/systemd.git/blob - .github/workflows/build_test.sh
Merge pull request #25168 from valentindavid/valentindavid/umount-move-recursive...
[thirdparty/systemd.git] / .github / workflows / build_test.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 set -ex
5
6 info() { echo -e "\033[33;1m$1\033[0m"; }
7 fatal() { echo >&2 -e "\033[31;1m$1\033[0m"; exit 1; }
8 success() { echo >&2 -e "\033[32;1m$1\033[0m"; }
9
10 ARGS=(
11 "--optimization=0"
12 "--optimization=s -Dgnu-efi=true -Defi-cflags=-m32 -Defi-libdir=/usr/lib32"
13 "--optimization=3 -Db_lto=true -Ddns-over-tls=false"
14 "--optimization=3 -Db_lto=false"
15 "--optimization=3 -Ddns-over-tls=openssl"
16 "--optimization=3 -Dfexecve=true -Dstandalone-binaries=true -Dstatic-libsystemd=true -Dstatic-libudev=true"
17 "-Db_ndebug=true"
18 )
19 PACKAGES=(
20 cryptsetup-bin
21 expect
22 fdisk
23 gettext
24 iputils-ping
25 isc-dhcp-client
26 itstool
27 kbd
28 libblkid-dev
29 libbpf-dev
30 libc6-dev-i386
31 libcap-dev
32 libcurl4-gnutls-dev
33 libfdisk-dev
34 libfido2-dev
35 libgpg-error-dev
36 liblz4-dev
37 liblzma-dev
38 libmicrohttpd-dev
39 libmount-dev
40 libp11-kit-dev
41 libpwquality-dev
42 libqrencode-dev
43 libssl-dev
44 libtss2-dev
45 libxen-dev
46 libxkbcommon-dev
47 libxtables-dev
48 libzstd-dev
49 mold
50 mount
51 net-tools
52 perl
53 python3-evdev
54 python3-jinja2
55 python3-lxml
56 python3-pefile
57 python3-pip
58 python3-pyparsing
59 python3-setuptools
60 quota
61 strace
62 unifont
63 util-linux
64 zstd
65 )
66 COMPILER="${COMPILER:?}"
67 COMPILER_VERSION="${COMPILER_VERSION:?}"
68 LINKER="${LINKER:?}"
69 CRYPTOLIB="${CRYPTOLIB:?}"
70 RELEASE="$(lsb_release -cs)"
71
72 bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ $RELEASE main restricted universe multiverse' >>/etc/apt/sources.list"
73
74 # Note: As we use postfixed clang/gcc binaries, we need to override $AR
75 # as well, otherwise meson falls back to ar from binutils which
76 # doesn't work with LTO
77 if [[ "$COMPILER" == clang ]]; then
78 CC="clang-$COMPILER_VERSION"
79 CXX="clang++-$COMPILER_VERSION"
80 AR="llvm-ar-$COMPILER_VERSION"
81
82 # Prefer the distro version if available
83 if ! apt install --dry-run "llvm-$COMPILER_VERSION" >/dev/null; then
84 # Latest LLVM stack deb packages provided by https://apt.llvm.org/
85 # Following snippet was partly borrowed from https://apt.llvm.org/llvm.sh
86 wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --yes --dearmor --output /usr/share/keyrings/apt-llvm-org.gpg
87 printf "deb [signed-by=/usr/share/keyrings/apt-llvm-org.gpg] http://apt.llvm.org/%s/ llvm-toolchain-%s-%s main\n" \
88 "$RELEASE" "$RELEASE" "$COMPILER_VERSION" >/etc/apt/sources.list.d/llvm-toolchain.list
89 fi
90
91 PACKAGES+=("clang-$COMPILER_VERSION" "lldb-$COMPILER_VERSION" "lld-$COMPILER_VERSION" "clangd-$COMPILER_VERSION")
92 elif [[ "$COMPILER" == gcc ]]; then
93 CC="gcc-$COMPILER_VERSION"
94 CXX="g++-$COMPILER_VERSION"
95 AR="gcc-ar-$COMPILER_VERSION"
96
97 if ! apt install --dry-run "gcc-$COMPILER_VERSION" >/dev/null; then
98 # Latest gcc stack deb packages provided by
99 # https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
100 add-apt-repository -y ppa:ubuntu-toolchain-r/test
101 fi
102
103 PACKAGES+=("gcc-$COMPILER_VERSION" "gcc-$COMPILER_VERSION-multilib")
104 else
105 fatal "Unknown compiler: $COMPILER"
106 fi
107
108 # PPA with some newer build dependencies (like zstd)
109 add-apt-repository -y ppa:upstream-systemd-ci/systemd-ci
110 apt-get -y update
111 apt-get -y build-dep systemd
112 apt-get -y install "${PACKAGES[@]}"
113 # Install more or less recent meson and ninja with pip, since the distro versions don't
114 # always support all the features we need (like --optimization=). Since the build-dep
115 # command above installs the distro versions, let's install the pip ones just
116 # locally and add the local bin directory to the $PATH.
117 pip3 install --user -r .github/workflows/requirements.txt --require-hashes
118 export PATH="$HOME/.local/bin:$PATH"
119
120 $CC --version
121 meson --version
122 ninja --version
123
124 for args in "${ARGS[@]}"; do
125 SECONDS=0
126
127 # The install_tag feature introduced in 0.60 causes meson to fail with fatal-meson-warnings
128 # "Project targeting '>= 0.53.2' but tried to use feature introduced in '0.60.0': install_tag arg in custom_target"
129 # It can be safely removed from the CI since it isn't actually used anywhere to test anything.
130 find . -type f -name meson.build -exec sed -i '/install_tag/d' '{}' '+'
131
132 # mold < 1.1 does not support LTO.
133 if dpkg --compare-versions "$(dpkg-query --showformat='${Version}' --show mold)" ge 1.1; then
134 fatal "Newer mold version detected, please remove this workaround."
135 elif [[ "$args" == *"-Db_lto=true"* ]]; then
136 LD="gold"
137 else
138 LD="$LINKER"
139 fi
140
141 info "Checking build with $args"
142 # shellcheck disable=SC2086
143 if ! AR="$AR" \
144 CC="$CC" CC_LD="$LD" CFLAGS="-Werror" \
145 CXX="$CXX" CXX_LD="$LD" CXXFLAGS="-Werror" \
146 meson setup \
147 -Dtests=unsafe -Dslow-tests=true -Dfuzz-tests=true --werror \
148 -Dnobody-group=nogroup -Dcryptolib="${CRYPTOLIB:?}" \
149 $args build; then
150
151 cat build/meson-logs/meson-log.txt
152 fatal "meson failed with $args"
153 fi
154
155 if ! meson compile -C build -v; then
156 fatal "'meson compile' failed with '$args'"
157 fi
158
159 for loader in build/src/boot/efi/*.efi; do
160 if sbverify --list "$loader" |& grep -q "gap in section table"; then
161 fatal "$loader: Gaps found in section table"
162 fi
163 done
164
165 git clean -dxf
166
167 success "Build with '$args' passed in $SECONDS seconds"
168 done