diff --git a/.gitlab-ci/common/README.md b/.gitlab-ci/common/README.md new file mode 100644 index 0000000..1f2dbd8 --- /dev/null +++ b/.gitlab-ci/common/README.md @@ -0,0 +1,20 @@ +common CI stuff - supposed to be synced across all drivers + +moving this to a dedicated CI component is left for a later exercise. + +Some scripts can also be used locally, eg. in a VM: + +Prepare the image: + + .gitlab-ci/common/debian/image-install.sh + .gitlab-ci/common/freebsd/image-install.sh + +Build the xserver + driver: + + .gitlab-ci/common/build-driver.sh debian + .gitlab-ci/common/build-driver.sh freebsd + +Build just the xserver: + + .gitlab-ci/common/build-xserver.sh debian + .gitlab-ci/common/build-xserver.sh freebsd diff --git a/.gitlab-ci/common/build-driver.sh b/.gitlab-ci/common/build-driver.sh new file mode 100755 index 0000000..a11427b --- /dev/null +++ b/.gitlab-ci/common/build-driver.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +set -e + +PLATFORM="$1" +XSERVER_REF="$2" + +if [ ! "$PLATFORM" ]; then + echo "missing PLATFORM" >&2 + exit 1 +fi + +if [ ! "$XSERVER_REF" ]; then + echo "missing XSERVER_REF" >&2 + exit 1 +fi + +.gitlab-ci/common/build-xserver.sh "$PLATFORM" "$XSERVER_REF" + +case "$PLATFORM" in + freebsd) + export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/libdata/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig" + export ACLOCAL_PATH="/usr/share/aclocal:/usr/local/share/aclocal" + export CFLAGS="$CFLAGS -I/usr/local/include" + export UDEV_CFLAGS=" " + export UDEV_LIBS=" " + ;; + debian) + export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/share/pkgconfig" + ;; + *) + echo "unknown platform $PLATFORM" >&2 + ;; +esac + +if [ -f autogen.sh ]; then + ( + echo "building driver via autotools" + rm -Rf _builddir + mkdir -p _builddir + cd _builddir + ../autogen.sh --disable-silent-rules + make + make check + make distcheck + ) +elif [ -f meson.build ]; then + ( + echo "building driver via meson" + meson setup _build + cd _build + meson compile + meson install + ) +else + echo "failed detecting build system" + exit 1 +fi diff --git a/.gitlab-ci/common/build-xserver.sh b/.gitlab-ci/common/build-xserver.sh new file mode 100755 index 0000000..7e21580 --- /dev/null +++ b/.gitlab-ci/common/build-xserver.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -e +set -x + +PLATFORM="$1" +XSERVER_REF="$2" + +if [ ! "$XSERVER_REF" ]; then + echo "missing XSERVER_REF variable" >&2 + exit 1 +fi + +XSERVER_CLONE=/tmp/xserver +XSERVER_BUILD=$XSERVER_CLONE/_builddir +XSERVER_REPO=https://gitlab.freedesktop.org/xorg/xserver.git + +MACH=`gcc -dumpmachine` + +export PKG_CONFIG_PATH="/usr/lib/$MACH/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH" +export PKG_CONFIG_PATH="/usr/local/lib/$MACH/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:$PKG_CONFIG_PATH" + +echo "cloning xserver" +rm -Rf $XSERVER_CLONE +git clone --depth=1 -b $XSERVER_REF $XSERVER_REPO $XSERVER_CLONE + +echo "checking platform: $PLATFORM" +case "$PLATFORM" in + freebsd) + echo "Building on FreeBSD" + XSERVER_OS_AUTOCONF_FLAGS="--without-dtrace" + XSERVER_MESON_DISABLE="glx udev udev_kms" + ;; + debian) + echo "Building on Debian" + ;; + *) + echo "unknown platform $PLATFORM" >&2 + exit 1 + ;; +esac + +if [ -f $XSERVER_CLONE/meson.build ]; then + ( + echo "Building Xserver via meson" + for opt in $XSERVER_MESON_DISABLE ; do + if grep "'$opt'" $XSERVER_CLONE/meson_options.txt ; then + echo "disable $opt" + XSERVER_MESON_FLAGS="$XSERVER_MESON_FLAGS -D$opt=false" + else + echo "no option $opt" + fi + done + mkdir -p $XSERVER_BUILD + cd $XSERVER_BUILD + meson setup --prefix=/usr $XSERVER_MESON_FLAGS + meson compile + meson install + ) +else + ( + echo "Building Xserver via autotools" + cd $XSERVER_CLONE + # Workaround glvnd having reset the version in gl.pc from what Mesa used + # similar to xserver commit e6ef2b12404dfec7f23592a3524d2a63d9d25802 + sed -i -e 's/gl >= [79].[12].0/gl >= 1.2/' configure.ac + ./autogen.sh --prefix=/usr $XSERVER_AUTOCONF_FLAGS $XSERVER_OS_AUTOCONF_FLAGS + make -j`nproc` + make -j`nproc` install + ) +fi diff --git a/.gitlab-ci/common/debian/image-install.sh b/.gitlab-ci/common/debian/image-install.sh new file mode 100755 index 0000000..d704614 --- /dev/null +++ b/.gitlab-ci/common/debian/image-install.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +set -e +set -o xtrace + +echo 'deb-src https://deb.debian.org/debian bullseye main' >>/etc/apt/sources.list.d/deb-src.list +echo 'deb-src https://deb.debian.org/debian bullseye-updates main' >>/etc/apt/sources.list.d/deb-src.list +apt-get update + +apt-get autoremove -y --purge + +apt-get install -y --no-remove \ + autoconf \ + automake \ + build-essential \ + libtool \ + pkg-config \ + ca-certificates \ + git \ + debian-archive-keyring \ + python3 python3-setuptools libxshmfence-dev \ + clang \ + libxvmc-dev libxcb1-dev libx11-xcb-dev libxcb-dri2-0-dev libxcb-util-dev \ + libxfixes-dev libxcb-xfixes0-dev libxrender-dev libxdamage-dev libxrandr-dev \ + libxcursor-dev libxss-dev libxinerama-dev libxtst-dev libpng-dev libssl-dev \ + libxcb-dri3-dev libxxf86vm-dev libxfont-dev libxkbfile-dev libdrm-dev \ + libgbm-dev libgl1-mesa-dev libpciaccess-dev libpixman-1-dev libudev-dev \ + libgcrypt-dev libepoxy-dev libevdev-dev libmtdev-dev libinput-dev \ + mesa-common-dev libspice-protocol-dev libspice-server-dev \ + meson \ + nettle-dev \ + pkg-config \ + valgrind \ + x11-xkb-utils xfonts-utils xutils-dev x11proto-dev + +build_autoconf() { + local subdir="$1" + shift + ( + cd $subdir + ./autogen.sh "$@" + make -j${FDO_CI_CONCURRENT:-4} + make -j${FDO_CI_CONCURRENT:-4} install + ) +} + +build_meson() { + local subdir="$1" + shift + ( + cd $subdir + meson _build -Dprefix=/usr "$@" + ninja -C _build -j${FDO_CI_CONCURRENT:-4} install + ) +} + +do_clone() { + git clone "$1" --depth 1 --branch="$2" +} + +mkdir -p /tmp/build-deps +cd /tmp/build-deps + +# xserver 1.18 and older branches require libXfont 1.5 instead of 2.0 +echo "Installing libXfont 1.5" +do_clone https://gitlab.freedesktop.org/xorg/lib/libXfont.git libXfont-1.5-branch +build_autoconf libXfont + +echo "Installing font-util" +do_clone https://gitlab.freedesktop.org/xorg/font/util.git font-util-1.4.1 +build_autoconf util --prefix=/usr + +echo "Installing libxcvt" +do_clone https://gitlab.freedesktop.org/xorg/lib/libxcvt.git libxcvt-0.1.0 +build_meson libxcvt + +# xserver requires xorgproto >= 2024.1 for XWAYLAND +echo "Installing xorgproto" +do_clone https://gitlab.freedesktop.org/xorg/proto/xorgproto.git xorgproto-2024.1 +build_autoconf xorgproto + +# Xwayland requires drm 2.4.116 for drmSyncobjEventfd +echo "Installing libdrm" +do_clone https://gitlab.freedesktop.org/mesa/drm libdrm-2.4.116 +build_meson drm + +rm -Rf /tmp/build-deps diff --git a/.gitlab-ci/common/freebsd/FreeBSD.conf b/.gitlab-ci/common/freebsd/FreeBSD.conf new file mode 100644 index 0000000..50a9bce --- /dev/null +++ b/.gitlab-ci/common/freebsd/FreeBSD.conf @@ -0,0 +1,8 @@ +# using the latest branch +FreeBSD: { + url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest", + mirror_type: "srv", + signature_type: "fingerprints", + fingerprints: "/usr/share/keys/pkg", + enabled: yes +} diff --git a/.gitlab-ci/common/freebsd/image-install.sh b/.gitlab-ci/common/freebsd/image-install.sh new file mode 100755 index 0000000..093eb75 --- /dev/null +++ b/.gitlab-ci/common/freebsd/image-install.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -e + +# note: really wanna install to /usr/local, since that's explicitly searched first, +# so we always catch the locally installed before any system/ports provided one +# otherwise we might run into trouble like trying to use outdated xorgproto +build_autoconf() { + local subdir="$1" + shift + ( + cd $subdir + ./autogen.sh --prefix=/usr/local "$@" + make -j${FDO_CI_CONCURRENT:-4} + make -j${FDO_CI_CONCURRENT:-4} install + ) +} + +build_meson() { + local subdir="$1" + shift + ( + cd $subdir + meson _build -Dprefix=/usr/local "$@" + ninja -C _build -j${FDO_CI_CONCURRENT:-4} install + ) +} + +do_clone() { + git clone "$1" --depth 1 --branch="$2" +} + +gpart recover ada0 +gpart resize -i 4 ada0 +growfs / + +cp .gitlab-ci/common/freebsd/FreeBSD.conf /etc/pkg + +pkg upgrade -f -y + +pkg install -y \ + git gcc pkgconf autoconf automake libtool xorg-macros xorgproto meson \ + ninja pixman xtrans libXau libXdmcp libXfont libXfont2 libxkbfile libxcvt \ + libpciaccess font-util libepoll-shim libdrm mesa-libs libdrm libglu mesa-dri \ + libepoxy nettle xkbcomp libXvMC xcb-util valgrind libXcursor libXScrnSaver \ + libXinerama libXtst evdev-proto libevdev libmtdev libinput spice-protocol \ + libspice-server + +[ -f /bin/bash ] || ln -sf /usr/local/bin/bash /bin/bash + +echo "=== post-install script END" diff --git a/.gitlab-ci/common/xorg-driver.yml b/.gitlab-ci/common/xorg-driver.yml new file mode 100644 index 0000000..86f883c --- /dev/null +++ b/.gitlab-ci/common/xorg-driver.yml @@ -0,0 +1,189 @@ +# version 0.1.16 +variables: + DEBIAN_VERSION: bullseye-slim + DEBIAN_TAG: "2024-06-06.02" + DEBIAN_EXEC: 'bash .gitlab-ci/common/debian/image-install.sh' + DEBIAN_SKIP: "false" # to enable, it has to be litterally "true" + + FREEBSD_TAG: '2024-06-06.02' + FREEBSD_VERSION: '14.0' +# image is yet too small for that - need a more complicated way :( +# FREEBSD_EXEC: "bash .gitlab-ci/common/freebsd/image-install.sh" + FREEBSD_SKIP: "false" # to enable, it has to be litterally "true" + +.templates_sha: &template_sha bc70242ffb8402243e934659ecc1a2d1c89eca2b # see https://docs.gitlab.com/ee/ci/yaml/#includefile + +include: + - project: 'freedesktop/ci-templates' + ref: *template_sha + file: '/templates/debian.yml' + - project: 'freedesktop/ci-templates' + ref: *template_sha + file: '/templates/freebsd.yml' + - project: 'freedesktop/ci-templates' + ref: *template_sha + file: '/templates/ci-fairy.yml' + - template: Security/SAST.gitlab-ci.yml + +stages: + - images + - build + - test + +# standard commits quality check +check-commits: + extends: + - .fdo.ci-fairy + stage: test + script: + - ci-fairy check-commits --junit-xml=results.xml + except: + - master@$FDO_UPSTREAM_REPO + variables: + GIT_DEPTH: 100 + artifacts: + reports: + junit: results.xml + allow_failure: true + needs: + +# standard merge request quality checks +check-merge-request: + extends: + - .fdo.ci-fairy + stage: test + script: + - ci-fairy check-merge-request --require-allow-collaboration --junit-xml=results.xml + artifacts: + when: on_failure + reports: + junit: results.xml + allow_failure: true + needs: + +# create debian build image +image@debian: + extends: + - .xorg.distro@debian + - .fdo.container-build@debian + stage: images + variables: + GIT_STRATEGY: none + rules: + - if: $DEBIAN_SKIP != "true" + when: always + needs: + +# inherit this to define FDO_DISTRIBUTION_* variables for Debian +.xorg.distro@debian: + variables: + FDO_DISTRIBUTION_VERSION: "$DEBIAN_VERSION" + FDO_DISTRIBUTION_EXEC: "$DEBIAN_EXEC" + FDO_DISTRIBUTION_TAG: "$DEBIAN_TAG" + +# overwrite this one if another matrix is needed +.xorg_driver_matrix@debian: + parallel: + matrix: + - CC: [ "gcc", "clang" ] + XSERVER_REF: [ +# these break on Debian +# "xorg-server-1.18.4", +# "xorg-server-1.19.7", + "xorg-server-1.20.14", + "xorg-server-21.1.13", + "master" + ] + +# default build with meson on Debian +.xorg_driver_common@debian: + needs: + - image@debian + extends: + - .xorg.distro@debian + - .fdo.distribution-image@debian + stage: build + script: + - .gitlab-ci/common/build-driver.sh "debian" "$XSERVER_REF" + variables: + CFLAGS: "-pipe -g -O2" + rules: + - if: $DEBIAN_SKIP != "true" + when: always + +# overwrite this when you need some special Debian build +build@debian: + extends: + - .xorg_driver_matrix@debian + - .xorg_driver_common@debian + +# inherit this to define FDO_DISTRIBUTION_* variables for FreeBSD +.xorg.distro@freebsd: + variables: + FDO_DISTRIBUTION_VERSION: "$FREEBSD_VERSION" + FDO_DISTRIBUTION_EXEC: "$FREEBSD_EXEC" + FDO_DISTRIBUTION_TAG: "$FREEBSD_TAG" + +# create base image for FreeBSD +image@freebsd: + extends: + - .xorg.distro@freebsd + - .fdo.qemu-build@freebsd@x86_64 + stage: images + variables: + GIT_STRATEGY: none + rules: + - if: $FREEBSD_SKIP != "true" + when: always + +# inherit this to get the default build matrix +.xorg_driver_matrix@freebsd: + parallel: + matrix: + - CC: [ "gcc", "clang" ] + XSERVER_REF: [ +# "xorg-server-1.18.4", # this breaks due name clash on "bool" +# "xorg-server-1.19.7", +# "xorg-server-1.20.14", # breaks meson ... see: 331850ce6f0c48a1cfc489da2a27ca0220997a2f -- server-1.20-branch + "xorg-server-21.0.99.1", + "xorg-server-21.1.13", + "master" + ] + +# common build for driver on FreeBSD. meson and autoconf are both handled by this +.xorg_driver_common@freebsd: + needs: + - image@freebsd + stage: build + extends: + - .fdo.distribution-image@freebsd + - .xorg.distro@freebsd + script: + # FIXME: increasing image and running image-install.sh should be done + # at container image build time, but would have to replicate too much + # of the cbuild script here. better wait until CI folks have increased + # the image size or provide hooks for that + - xz -d -T0 /app/image.raw.xz + - rm -f /app/image.raw.xz + - truncate -s +5G /app/image.raw + - /app/vmctl start + - set +e + - /app/vmctl exec "gpart recover /dev/ada0 && gpart resize -i4 /dev/ada0 && growfs -y /" + - scp -r $PWD "vm:" + - /app/vmctl exec "cd $CI_PROJECT_NAME && .gitlab-ci/common/freebsd/image-install.sh" + - /app/vmctl exec "cd $CI_PROJECT_NAME && .gitlab-ci/common/build-driver.sh freebsd $XSERVER_REF" && touch .success + # copy any test results from the VM to our container so we can + # save them as artifacts + - scp -r vm:$CI_PROJECT_NAME/test-results.xml . || true # this is allowed to fail + - /app/vmctl stop + - set -e + - test -e .success || exit 1 + rules: + - if: $FREEBSD_SKIP != "true" + when: always + +# overwrite this if you need some special FreeBSD build +build@freebsd: + extends: + - .xorg_driver_matrix@freebsd + - .xorg_driver_common@freebsd