From: Yu Watanabe Date: Tue, 9 Sep 2025 04:42:24 +0000 (+0900) Subject: musl: ci: add build test and unit tests X-Git-Tag: v259-rc1~30^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f115763f191c45dc761aab071705385e78d9a3c5;p=thirdparty%2Fsystemd.git musl: ci: add build test and unit tests --- diff --git a/.github/workflows/build-test-musl.sh b/.github/workflows/build-test-musl.sh new file mode 100755 index 00000000000..f0f72d6e03e --- /dev/null +++ b/.github/workflows/build-test-musl.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1-or-later + +set -eux + +if ! command -v musl-gcc >/dev/null; then + echo "musl-gcc is not installed, skipping the test." + exit 77 +fi + +TMPDIR=$(mktemp -d) + +cleanup() ( + set +e + + if [[ -d "$TMPDIR" ]]; then + rm -rf "$TMPDIR" + fi +) + +trap cleanup EXIT ERR INT TERM + +mkdir -p "${TMPDIR}/build" +mkdir -p "${TMPDIR}/usr/include" +mkdir -p "${TMPDIR}/usr/lib64/pkgconfig" + +CFLAGS="-idirafter ${TMPDIR}/usr/include" +export PKG_CONFIG_PATH="${TMPDIR}"/usr/lib64/pkgconfig + +LINKS=( + acl + archive.h + archive_entry.h + asm + asm-generic + audit-records.h + audit_logging.h + bpf + bzlib.h + curl + dwarf.h + elfutils + fido.h + gcrypt.h + gelf.h + gnutls + gpg-error.h + idn2.h + libaudit.h + libcryptsetup.h + libelf.h + libkmod.h + linux + lz4.h + lz4frame.h + lz4hc.h + lzma + lzma.h + microhttpd.h + mtd + openssl + pcre2.h + pwquality.h + qrencode.h + seccomp-syscalls.h + seccomp.h + security + selinux + sys/acl.h + sys/capability.h + tss2 + xen + xkbcommon + zconf.h + zlib.h + zstd.h + zstd_errors.h +) + +for t in "${LINKS[@]}"; do + [[ -e /usr/include/"$t" ]] + link="${TMPDIR}"/usr/include/"${t}" + mkdir -p "${link%/*}" + ln -s /usr/include/"$t" "$link" +done + +env \ + CC=musl-gcc \ + CXX=musl-gcc \ + CFLAGS="$CFLAGS" \ + CXXFLAGS="$CFLAGS" \ + meson setup --werror -Ddbus-interfaces-dir=no -Dlibc=musl "${TMPDIR}"/build + +ninja -v -C "${TMPDIR}"/build diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index c107b2da1ec..c99d34705ad 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -49,6 +49,10 @@ jobs: [Build] ToolsTreeDistribution=fedora ToolsTreeRelease=rawhide + ToolsTreePackages= + libgcrypt-devel + libgpg-error-devel + musl-gcc EOF mkosi -f box -- true @@ -77,3 +81,6 @@ jobs: - name: Run clang-tidy run: mkosi box -- meson test -C build --suite=clang-tidy --print-errorlogs --no-stdsplit + + - name: Build with musl + run: mkosi box -- .github/workflows/build-test-musl.sh diff --git a/.github/workflows/unit-tests-musl.sh b/.github/workflows/unit-tests-musl.sh new file mode 100755 index 00000000000..c3307a62b31 --- /dev/null +++ b/.github/workflows/unit-tests-musl.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later + +# shellcheck disable=SC2206 +PHASES=(${@:-SETUP BUILD RUN CLEANUP}) + +function info() { + echo -e "\033[33;1m$1\033[0m" +} + +function run_meson() { + if ! meson "$@"; then + find . -type f -name meson-log.txt -exec cat '{}' + + return 1 + fi +} + +set -ex + +for phase in "${PHASES[@]}"; do + case $phase in + SETUP) + info "Setup phase" + + # Alpine still uses split-usr. + for i in /bin/* /sbin/*; do + ln -rs "$i" "/usr/$i"; + done + ;; + BUILD) + info "Build systemd phase" + + run_meson setup --werror -Dtests=unsafe -Dslow-tests=true -Dfuzz-tests=true -Dlibc=musl build + ninja -v -C build + ;; + RUN) + info "Run phase" + + # Create dummy machine ID. + echo '052e58f661f94bd080e258b96aea3f7b' > /etc/machine-id + + # Start dbus for several unit tests. + mkdir -p /var/run/dbus + /usr/bin/dbus-daemon --system || : + + # Here, we explicitly set SYSTEMD_IN_CHROOT=yes as unfortunately runnin_in_chroot() does not + # correctly detect the environment. + env \ + SYSTEMD_IN_CHROOT=yes \ + meson test -C build --print-errorlogs + ;; + CLEANUP) + info "Cleanup phase" + ;; + *) + echo >&2 "Unknown phase '$phase'" + exit 1 + esac +done diff --git a/.github/workflows/unit-tests-musl.yml b/.github/workflows/unit-tests-musl.yml new file mode 100644 index 00000000000..fca3eef019d --- /dev/null +++ b/.github/workflows/unit-tests-musl.yml @@ -0,0 +1,113 @@ +--- +# vi: ts=2 sw=2 et: +# SPDX-License-Identifier: LGPL-2.1-or-later +# +name: Unit tests (musl) +on: + pull_request: + paths: + - '**/meson.build' + - '.github/workflows/**' + - 'meson_options.txt' + - 'src/**' + - 'test/fuzz/**' + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Repository checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Install build dependencies + uses: jirutka/setup-alpine@v1 + with: + arch: x86_64 + branch: edge + packages: > + acl + acl-dev + audit-dev + bash + bash-completion-dev + bpftool + build-base + bzip2-dev + coreutils + cryptsetup-dev + curl-dev + dbus + dbus-dev + elfutils-dev + gettext-dev + git + glib-dev + gnutls-dev + gperf + grep + iproute2 + iptables-dev + kbd + kexec-tools + kmod + kmod-dev + libapparmor-dev + libarchive-dev + libbpf-dev + libcap-dev + libcap-utils + libfido2-dev + libgcrypt-dev + libidn2-dev + libmicrohttpd-dev + libpwquality-dev + libqrencode-dev + libseccomp-dev + libselinux-dev + libxkbcommon-dev + linux-pam-dev + lz4-dev + meson + openssl + openssl-dev + p11-kit-dev + pcre2-dev + pkgconf + polkit-dev + py3-elftools + py3-jinja2 + py3-pefile + py3-pytest + py3-lxml + quota-tools + rsync + sfdisk + tpm2-tss-dev + tpm2-tss-esys + tpm2-tss-rc + tpm2-tss-tcti-device + tzdata + util-linux-dev + util-linux-login + util-linux-misc + utmps-dev + valgrind-dev + xen-dev + zlib-dev + zstd-dev + + - name: Setup + run: .github/workflows/unit-tests-musl.sh SETUP + shell: alpine.sh --root {0} + - name: Build + run: .github/workflows/unit-tests-musl.sh BUILD + shell: alpine.sh {0} + - name: Run + run: .github/workflows/unit-tests-musl.sh RUN + shell: alpine.sh --root {0} + - name: Cleanup + run: .github/workflows/unit-tests-musl.sh CLEANUP + shell: alpine.sh --root {0}