diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fdf64bf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,256 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# +# Loosely based on: https://github.com/linux-test-project/ltp +# https://github.com/linux-nfc/neard +# +name: "Builds" +on: + pull_request: + push: + schedule: + # Run at 1:01 PM, every Tuesday + - cron: '1 13 * * 2' + workflow_dispatch: + +jobs: + job: + name: Build + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + arch: [x86-64] + family: [x86-64] + compiler: [gcc, clang] + container: + - archlinux:latest + - debian:testing + - debian:stable + - debian:bookworm + - debian:bullseye + # Fails on configure on GCC and clang (process restrictions?) + # - fedora:rawhide + - fedora:latest + - fedora:39 + - fedora:38 + - fedora:37 + - ubuntu:lunar # EOL 01.2024 + - ubuntu:jammy + - ubuntu:focal + # On Ubuntu Bionic the Meson doesn't support feature options + #- ubuntu:bionic + # Meson version on Ubuntu Xenial is really too old + #- ubuntu:xenial + cross_compile: [""] + variant: [""] + nosystemd: [""] + include: + # Alpine (OpenRC) + - container: "alpine:edge" + arch: x86-64 + family: x86-64 + compiler: gcc + nosystemd: true + + - container: "alpine:latest" + arch: x86-64 + family: x86-64 + compiler: gcc + nosystemd: true + + # Debian 32-bit builds + - container: "debian:testing" + arch: i386 + family: x86 + compiler: gcc + cross_compile: i686-linux-gnu + pkg_config_path: /usr/lib/i386-linux-gnu/pkgconfig + variant: i386 + + - container: "debian:stable" + arch: i386 + family: x86 + compiler: gcc + cross_compile: i686-linux-gnu + pkg_config_path: /usr/lib/i386-linux-gnu/pkgconfig + variant: i386 + + - container: "debian:bookworm" + arch: i386 + family: x86 + compiler: gcc + cross_compile: i686-linux-gnu + pkg_config_path: /usr/lib/i386-linux-gnu/pkgconfig + variant: i386 + + # Debian cross compilation builds + - container: "debian:testing" + arch: armhf + family: arm + compiler: arm-linux-gnueabihf-gcc + cross_compile: arm-linux-gnueabihf + pkg_config_path: /usr/lib/arm-linux-gnueabihf/pkgconfig + variant: cross-compile + + - container: "debian:testing" + arch: arm64 + family: aarch64 + compiler: aarch64-linux-gnu-gcc + cross_compile: aarch64-linux-gnu + pkg_config_path: /usr/lib/aarch64-linux-gnu/pkgconfig + variant: cross-compile + + - container: "debian:testing" + arch: ppc64el + family: ppc64 + compiler: powerpc64le-linux-gnu-gcc + cross_compile: powerpc64le-linux-gnu + pkg_config_path: /usr/lib/powerpc64le-linux-gnu/pkgconfig + variant: cross-compile + + - container: "debian:testing" + arch: s390x + family: s390x + compiler: s390x-linux-gnu-gcc + cross_compile: s390x-linux-gnu + pkg_config_path: /usr/lib/s390x-linux-gnu/pkgconfig + variant: cross-compile + + - container: "debian:stable" + arch: armhf + family: arm + compiler: arm-linux-gnueabihf-gcc + cross_compile: arm-linux-gnueabihf + pkg_config_path: /usr/lib/arm-linux-gnueabihf/pkgconfig + variant: cross-compile + + - container: "debian:stable" + arch: arm64 + family: aarch64 + compiler: aarch64-linux-gnu-gcc + cross_compile: aarch64-linux-gnu + pkg_config_path: /usr/lib/aarch64-linux-gnu/pkgconfig + variant: cross-compile + + - container: "debian:stable" + arch: ppc64el + family: ppc64 + compiler: powerpc64le-linux-gnu-gcc + cross_compile: powerpc64le-linux-gnu + pkg_config_path: /usr/lib/powerpc64le-linux-gnu/pkgconfig + variant: cross-compile + + - container: "debian:stable" + arch: s390x + family: s390x + compiler: s390x-linux-gnu-gcc + cross_compile: s390x-linux-gnu + pkg_config_path: /usr/lib/s390x-linux-gnu/pkgconfig + variant: cross-compile + + container: + image: ${{ matrix.container }} + env: + ARCH: ${{ matrix.arch }} + FAMILY: ${{ matrix.family }} + CC: ${{ matrix.compiler }} + CROSS_COMPILE: ${{ matrix.cross_compile }} + PKG_CONFIG_PATH: ${{ matrix.pkg_config_path }} + VARIANT: ${{ matrix.variant }} + + steps: + - name: Show OS + run: cat /etc/os-release + + - name: Show env (matrix settings) + run: | + echo "ARCH: $ARCH" + echo "FAMILY: $FAMILY" + echo "CC: $CC" + echo "CROSS_COMPILE: $CROSS_COMPILE" + echo "VARIANT: $VARIANT" + echo "PKG_CONFIG_PATH: $PKG_CONFIG_PATH" + + - name: Git checkout + uses: actions/checkout@v3 + + - name: Install additional packages + run: | + INSTALL=${{ matrix.container }} + INSTALL="${INSTALL%%:*}" + INSTALL="${INSTALL%%/*}" + ./ci/$INSTALL.sh + if [ "$VARIANT" ]; then ./ci/$INSTALL.$VARIANT.sh; fi + + - name: Compiler version + run: $CC --version + + - name: Display environment and Linux version + run: | + test -f /etc/issue && cat /etc/issue + echo "############################################" + lsb_release -a || true + echo "############################################" + cat /usr/include/linux/version.h + echo "############################################" + uname -a + echo "############################################" + cat /proc/cmdline + echo "############################################" + printenv + + - name: Disable systemd + if: ${{ matrix.nosystemd == true }} + run: | + touch .nosystemd + + # i386 build on x86_64 only requires passing -m32 to CFLAGS & LDFLAGS + - name: Meson init for i386 + if: ${{ matrix.variant == 'i386' }} + run: | + if [ -f .nosystemd ]; then export BUILD_OPTIONS="-Dsystemd-service=disabled"; fi + mkdir build + CFLAGS="-m32" LDFLAGS="-m32" meson setup $BUILD_OPTIONS --errorlogs --werror . build + + - name: Meson init with cross compile + if: ${{ matrix.variant == 'cross-compile' }} + run: | + if [ -f .nosystemd ]; then export BUILD_OPTIONS="-Dsystemd-service=disabled"; fi + # Generate cross compile file (see https://mesonbuild.com/Cross-compilation.html#cross-compilation) + echo "[binaries]" > cross.txt + echo "c = '${CROSS_COMPILE}-gcc'" >> cross.txt + echo "strip = '${CROSS_COMPILE}-strip'" >> cross.txt + # Forcing pkgconfig binary to 'pkg-config' is required for cross build to work + echo "pkgconfig = 'pkg-config'" >> cross.txt + echo "[host_machine]" >> cross.txt + echo "system = 'linux'" >> cross.txt + echo "cpu_family = '${FAMILY}'" >> cross.txt + echo "cpu = '${ARCH}'" >> cross.txt + echo "endian = 'little'" >> cross.txt + echo "[properties]" >> cross.txt + echo "pkg_config_libdir = '${PKG_CONFIG_PATH}'" >> cross.txt + cat cross.txt + mkdir build + meson setup $BUILD_OPTIONS --errorlogs --werror --cross-file cross.txt . build + + - name: Meson init + if: ${{ matrix.variant == '' }} + run: | + if [ -f .nosystemd ]; then export BUILD_OPTIONS="-Dsystemd-service=disabled"; fi + mkdir build + meson setup $BUILD_OPTIONS --errorlogs --werror . build + + - name: Compile + run: ninja -C build + + - name: Install + run: ninja -C build install diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..92f7cd0 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# +name: "CodeQL" +on: [push, pull_request, workflow_dispatch] + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + + - name: Install additional packages + run: sudo ./ci/ubuntu.sh + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/ci/alpine.sh b/ci/alpine.sh new file mode 100755 index 0000000..be24904 --- /dev/null +++ b/ci/alpine.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# + +set -ex + +PKGS_CC="gcc" +case $CC in + clang*) + PKGS_CC="clang" + ;; +esac + +apk add \ + linux-headers \ + meson \ + musl-dev \ + libc-dev \ + $PKGS_CC + +echo "Install finished: $0" diff --git a/ci/archlinux.sh b/ci/archlinux.sh new file mode 100755 index 0000000..98eb82d --- /dev/null +++ b/ci/archlinux.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# + +set -ex + +PKGS_CC="gcc" +case $CC in + clang*) + PKGS_CC="clang" + ;; +esac + +pacman -Syu --noconfirm \ + systemd-libs \ + pkgconf \ + meson \ + $PKGS_CC + +echo "Install finished: $0" diff --git a/ci/debian.cross-compile.sh b/ci/debian.cross-compile.sh new file mode 100755 index 0000000..bf71b02 --- /dev/null +++ b/ci/debian.cross-compile.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2018-2020 Petr Vorel +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# + +set -ex + +if [ -z "$ARCH" ]; then + echo "missing \$ARCH!" >&2 + exit 1 +fi + +dpkg --add-architecture $ARCH +apt update + +apt install -y --no-install-recommends \ + gcc-`dpkg-architecture -a ${ARCH} -q DEB_TARGET_GNU_TYPE` + +# Thanks debian +apt install -y --no-install-recommends systemd-dev:${ARCH} -a ${ARCH} || true + +echo "Install finished: $0" diff --git a/ci/debian.i386.sh b/ci/debian.i386.sh new file mode 100755 index 0000000..611b348 --- /dev/null +++ b/ci/debian.i386.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2018-2020 Petr Vorel +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# + +set -ex + +dpkg --add-architecture i386 +apt update + +# gcc-multilib are also needed for clang 32-bit builds +PKGS_CC="gcc-multilib" + +apt install -y --no-install-recommends \ + linux-libc-dev:i386 + +apt install -y --no-install-recommends \ + $PKGS_CC + +echo "Install finished: $0" diff --git a/ci/debian.sh b/ci/debian.sh new file mode 100755 index 0000000..0bef8d2 --- /dev/null +++ b/ci/debian.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# + +set -ex + +apt update + +# Some distros (e.g. Ubuntu Hirsute) might pull tzdata which asks questions +export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true + +# Choose some random place in Europe +echo "tzdata tzdata/Areas select Europe +tzdata tzdata/Zones/Europe select Berlin +" > /tmp/tzdata-preseed.txt +debconf-set-selections /tmp/tzdata-preseed.txt + +PKGS_CC="build-essential" +case $CC in + clang*) + PKGS_CC="clang" + ;; +esac + +apt install -y --no-install-recommends \ + pkg-config \ + meson \ + systemd \ + $PKGS_CC + +# Thanks debian +apt install -y --no-install-recommends systemd-dev || true + +echo "Install finished: $0" diff --git a/ci/fedora.sh b/ci/fedora.sh new file mode 100755 index 0000000..d8ee851 --- /dev/null +++ b/ci/fedora.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2021 Canonical Ltd. +# Copyright (c) 2023 Linaro Ltd +# Author: Krzysztof Kozlowski +# +# + +set -ex + +PKGS_CC="gcc" +case $CC in + clang*) + PKGS_CC="clang" + ;; +esac + +dnf -y install \ + meson \ + pkg-config \ + libudev-devel \ + systemd-devel \ + systemd-libs \ + $PKGS_CC + +echo "Install finished: $0" diff --git a/ci/ubuntu.cross-compile.sh b/ci/ubuntu.cross-compile.sh new file mode 120000 index 0000000..18f77ad --- /dev/null +++ b/ci/ubuntu.cross-compile.sh @@ -0,0 +1 @@ +debian.cross-compile.sh \ No newline at end of file diff --git a/ci/ubuntu.sh b/ci/ubuntu.sh new file mode 120000 index 0000000..0edcb8b --- /dev/null +++ b/ci/ubuntu.sh @@ -0,0 +1 @@ +debian.sh \ No newline at end of file