2021-12-12 22:27:04 +03:00
#!/usr/bin/env bash
2021-10-01 13:10:22 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2020-06-10 14:41:28 +03:00
2020-06-11 14:18:07 +03:00
set -ex
2020-06-10 14:41:28 +03:00
2024-11-04 23:26:34 +03:00
shopt -s nullglob
2020-06-10 14:41:28 +03:00
info( ) { echo -e " \033[33;1m $1 \033[0m " ; }
2020-06-11 14:18:07 +03:00
fatal( ) { echo >& 2 -e " \033[31;1m $1 \033[0m " ; exit 1; }
2020-06-10 14:41:28 +03:00
success( ) { echo >& 2 -e " \033[32;1m $1 \033[0m " ; }
ARGS = (
2023-10-27 13:47:43 +03:00
"--optimization=0 -Dopenssl=disabled -Dcryptolib=gcrypt -Ddns-over-tls=gnutls -Dtpm=true -Dtpm2=enabled"
2023-11-08 21:41:09 +03:00
"--optimization=s -Dutmp=false"
2024-01-04 19:51:40 +03:00
"--optimization=2 -Dc_args=-Wmaybe-uninitialized -Ddns-over-tls=openssl"
2021-12-24 13:50:37 +03:00
"--optimization=3 -Db_lto=true -Ddns-over-tls=false"
2024-11-04 22:43:02 +03:00
"--optimization=3 -Db_lto=false -Dtpm2=disabled -Dlibfido2=disabled -Dp11kit=disabled -Defi=false -Dbootloader=disabled"
2021-05-05 22:07:36 +03:00
"--optimization=3 -Dfexecve=true -Dstandalone-binaries=true -Dstatic-libsystemd=true -Dstatic-libudev=true"
2020-06-10 14:41:28 +03:00
"-Db_ndebug=true"
)
PACKAGES = (
cryptsetup-bin
2020-06-10 21:51:15 +03:00
expect
fdisk
2020-06-10 14:41:28 +03:00
gettext
iputils-ping
isc-dhcp-client
itstool
kbd
libblkid-dev
2021-12-03 18:30:56 +03:00
libbpf-dev
2020-06-10 14:41:28 +03:00
libcap-dev
libcurl4-gnutls-dev
2020-06-10 21:51:15 +03:00
libfdisk-dev
2020-10-21 17:28:22 +03:00
libfido2-dev
2020-06-10 14:41:28 +03:00
libgpg-error-dev
liblz4-dev
liblzma-dev
libmicrohttpd-dev
libmount-dev
2020-06-10 21:51:15 +03:00
libp11-kit-dev
libpwquality-dev
2020-06-10 14:41:28 +03:00
libqrencode-dev
2020-06-10 21:51:15 +03:00
libssl-dev
2020-12-21 00:27:36 +03:00
libtss2-dev
2022-11-01 18:53:02 +03:00
libxen-dev
2020-06-10 14:41:28 +03:00
libxkbcommon-dev
2020-10-21 17:17:29 +03:00
libxtables-dev
2020-10-21 17:28:22 +03:00
libzstd-dev
2024-10-24 12:27:16 +03:00
mold
2020-06-10 14:41:28 +03:00
mount
net-tools
python3-evdev
2021-05-17 11:36:30 +03:00
python3-jinja2
2021-12-03 18:30:56 +03:00
python3-lxml
2022-11-25 21:14:42 +03:00
python3-pefile
2020-06-10 14:41:28 +03:00
python3-pip
2023-03-02 17:41:17 +03:00
python3-pyelftools
2020-06-10 14:41:28 +03:00
python3-pyparsing
python3-setuptools
quota
strace
unifont
util-linux
2020-06-10 21:51:15 +03:00
zstd
2020-06-10 14:41:28 +03:00
)
2020-06-11 14:18:07 +03:00
COMPILER = " ${ COMPILER : ? } "
COMPILER_VERSION = " ${ COMPILER_VERSION : ? } "
2021-12-10 20:28:33 +03:00
LINKER = " ${ LINKER : ? } "
2021-12-24 13:50:37 +03:00
CRYPTOLIB = " ${ CRYPTOLIB : ? } "
2020-06-10 14:41:28 +03:00
RELEASE = " $( lsb_release -cs) "
2020-06-11 14:18:07 +03:00
# Note: As we use postfixed clang/gcc binaries, we need to override $AR
# as well, otherwise meson falls back to ar from binutils which
# doesn't work with LTO
if [ [ " $COMPILER " = = clang ] ] ; then
CC = " clang- $COMPILER_VERSION "
CXX = " clang++- $COMPILER_VERSION "
AR = " llvm-ar- $COMPILER_VERSION "
2021-10-11 22:12:42 +03:00
2024-06-07 11:55:53 +03:00
if systemd-analyze compare-versions " $COMPILER_VERSION " ge 17; then
CFLAGS = "-fno-sanitize=function"
CXXFLAGS = "-fno-sanitize=function"
else
CFLAGS = ""
CXXFLAGS = ""
fi
2022-05-21 17:35:55 +03:00
# Prefer the distro version if available
2023-09-05 13:02:05 +03:00
if ! apt-get -y install --dry-run " llvm- $COMPILER_VERSION " >/dev/null; then
2021-10-11 22:12:42 +03:00
# Latest LLVM stack deb packages provided by https://apt.llvm.org/
2021-12-26 04:11:00 +03:00
# Following snippet was partly borrowed from https://apt.llvm.org/llvm.sh
2023-09-05 13:07:01 +03:00
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | \
sudo gpg --yes --dearmor --output /usr/share/keyrings/apt-llvm-org.gpg
echo " deb [signed-by=/usr/share/keyrings/apt-llvm-org.gpg] http://apt.llvm.org/ $RELEASE / llvm-toolchain- $RELEASE - $COMPILER_VERSION main " | \
sudo tee /etc/apt/sources.list.d/llvm-toolchain.list
2021-10-11 22:12:42 +03:00
fi
2022-05-21 17:35:55 +03:00
2023-07-27 14:20:17 +03:00
PACKAGES += ( " clang- $COMPILER_VERSION " " lldb- $COMPILER_VERSION " " python3-lldb- $COMPILER_VERSION " " lld- $COMPILER_VERSION " " clangd- $COMPILER_VERSION " )
2020-06-11 14:18:07 +03:00
elif [ [ " $COMPILER " = = gcc ] ] ; then
CC = " gcc- $COMPILER_VERSION "
CXX = " g++- $COMPILER_VERSION "
AR = " gcc-ar- $COMPILER_VERSION "
2024-06-07 11:55:53 +03:00
CFLAGS = ""
CXXFLAGS = ""
2022-05-07 15:40:56 +03:00
2023-09-05 13:02:05 +03:00
if ! apt-get -y install --dry-run " gcc- $COMPILER_VERSION " >/dev/null; then
2022-05-07 15:40:56 +03:00
# Latest gcc stack deb packages provided by
# https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
2023-09-05 13:07:01 +03:00
sudo add-apt-repository -y --no-update ppa:ubuntu-toolchain-r/test
2022-05-07 15:40:56 +03:00
fi
2022-03-23 16:40:06 +03:00
PACKAGES += ( " gcc- $COMPILER_VERSION " " gcc- $COMPILER_VERSION -multilib " )
2020-06-11 14:18:07 +03:00
else
fatal " Unknown compiler: $COMPILER "
fi
2024-04-24 17:33:31 +03:00
# This is added by default, and it is often broken, but we don't need anything from it
2024-06-07 11:55:53 +03:00
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.{ list,sources}
# add-apt-repository --enable-source does not work on deb822 style sources.
for f in /etc/apt/sources.list.d/*.sources; do
sudo sed -i "s/Types: deb/Types: deb deb-src/g" " $f "
done
2023-09-05 13:07:01 +03:00
sudo apt-get -y update
sudo apt-get -y build-dep systemd
sudo apt-get -y install " ${ PACKAGES [@] } "
2021-11-19 19:23:03 +03:00
# Install more or less recent meson and ninja with pip, since the distro versions don't
# always support all the features we need (like --optimization=). Since the build-dep
2020-06-11 16:00:15 +03:00
# command above installs the distro versions, let's install the pip ones just
# locally and add the local bin directory to the $PATH.
2024-06-07 11:55:53 +03:00
pip3 install --user -r .github/workflows/requirements.txt --require-hashes --break-system-packages
2020-06-11 16:00:15 +03:00
export PATH = " $HOME /.local/bin: $PATH "
2020-06-10 14:41:28 +03:00
$CC --version
2021-01-25 18:01:56 +03:00
meson --version
ninja --version
2020-06-10 14:41:28 +03:00
for args in " ${ ARGS [@] } " ; do
SECONDS = 0
2024-01-04 19:51:40 +03:00
if [ [ " $COMPILER " = = clang && " $args " = ~ Wmaybe-uninitialized ] ] ; then
# -Wmaybe-uninitialized is not implemented in clang
continue
fi
2020-06-10 14:41:28 +03:00
info " Checking build with $args "
2021-09-29 20:55:24 +03:00
# shellcheck disable=SC2086
2021-12-10 20:28:33 +03:00
if ! AR = " $AR " \
2024-06-07 11:55:53 +03:00
CC = " $CC " CC_LD = " $LINKER " CFLAGS = " $CFLAGS " \
CXX = " $CXX " CXX_LD = " $LINKER " CXXFLAGS = " $CXXFLAGS " \
2023-01-11 17:04:11 +03:00
meson setup \
-Dtests= unsafe -Dslow-tests= true -Dfuzz-tests= true --werror \
2023-09-05 13:03:13 +03:00
-Dnobody-group= nogroup -Dcryptolib= " ${ CRYPTOLIB : ? } " -Ddebug= false \
2022-08-10 10:47:42 +03:00
$args build; then
2021-12-10 20:28:33 +03:00
2022-01-13 10:01:17 +03:00
cat build/meson-logs/meson-log.txt
2020-06-11 14:18:07 +03:00
fatal " meson failed with $args "
2020-06-10 14:41:28 +03:00
fi
2022-01-13 10:01:17 +03:00
if ! meson compile -C build -v; then
2023-01-11 17:04:11 +03:00
fatal " 'meson compile' failed with ' $args ' "
2020-06-10 14:41:28 +03:00
fi
2023-03-02 17:41:17 +03:00
for loader in build/src/boot/efi/*{ .efi,.efi.stub} ; do
if [ [ " $( sbverify --list " $loader " 2>& 1) " != "No signature table present" ] ] ; then
2022-01-02 22:05:58 +03:00
fatal " $loader : Gaps found in section table "
fi
done
2020-06-10 14:41:28 +03:00
git clean -dxf
2023-01-11 17:04:11 +03:00
success " Build with ' $args ' passed in $SECONDS seconds "
2020-06-10 14:41:28 +03:00
done