#!/usr/bin/env bash # Build and test the tree in throwaway containers, one leg per distro x compiler, before a release # or a ci/** push. Catches what the one-distro dev container cannot: a newer libstdc++/GCC (forky), # clang-only diagnostics, library API drift (libbpf, yara). # # scripts/compiler_matrix.sh # all legs # scripts/compiler_matrix.sh forky-gcc noble-clang # scripts/compiler_matrix.sh --list # # Legs: -, os in trixie noble forky (the release targets), compiler in gcc clang. # Each leg copies the working tree (no builddir*, no .git) into the container, runs meson setup, # ninja -k 0 (every compile error, not only the first) and meson test. Logs and summary.txt go to # builddir-matrix/. Exit 0 only when every leg built and passed its tests. # # Env: # JOBS=4 ninja / meson test parallelism per leg # MATRIX_CPUS=4 docker --cpus per leg (legs run one at a time) # MATRIX_MEMORY=8g docker --memory per leg # MATRIX_TESTS=1 0 = build only # MATRIX_PLATFORM= e.g. linux/amd64 to match CI on an arm64 host (slow: emulated) # MATRIX_REFRESH=0 1 = re-pull the base image and reinstall packages (forky moves: use it # before a release so the leg sees today's testing) # MATRIX_OUT=builddir-matrix # Bash 3.2 compatible (macOS /bin/bash). set -euo pipefail cd "$(dirname "$0")/.." # noble's default clang 18 cannot use libstdc++ 13's std::expected; its clang leg uses clang-19 (+ llvm-19: # the archiver must read clang-19's LTO bitcode). extra_of() { case "$1" in noble) echo clang-19 llvm-19 ;; esac } base_of() { case "$1" in trixie) echo debian:trixie ;; noble) echo ubuntu:24.04 ;; forky) echo debian:forky ;; esac } ALL="trixie-gcc trixie-clang noble-gcc noble-clang forky-gcc forky-clang" # shellcheck disable=SC2086 # word lists split on purpose if [ "${1:-}" = "--list" ]; then printf '%s\n' $ALL; exit 0; fi legs="$*" [ -n "$legs" ] || legs=$ALL for leg in $legs; do case " $ALL " in *" $leg "*) ;; *) echo "unknown leg: $leg (try --list)" >&2; exit 2 ;; esac done command -v docker >/dev/null || { echo "docker not found" >&2; exit 2; } jobs=${JOBS:-4} cpus=${MATRIX_CPUS:-4} mem=${MATRIX_MEMORY:-8g} tests=${MATRIX_TESTS:-1} out=${MATRIX_OUT:-builddir-matrix} plat="" [ -z "${MATRIX_PLATFORM:-}" ] || plat="--platform=$MATRIX_PLATFORM" mkdir -p "$out" summary="$out/summary.txt" # Runs inside the container (expanded there, hence single quotes); the source is mounted read-only at /src. # shellcheck disable=SC2016 LEG_SCRIPT='set -uo pipefail tar -C /src --exclude=./builddir* --exclude=./.git --exclude=./.ccache -cf - . | tar -C /w -xf - case "$COMPILER" in gcc) export CC=gcc CXX=g++ ;; clang) # newest versioned clang in the image (noble: clang-19 over the default 18) v=$(ls /usr/bin/clang++-[0-9]* 2>/dev/null | sed "s#.*clang++-##" | sort -n | tail -1) if [ -n "$v" ]; then export CC=clang-$v CXX=clang++-$v # LTO objects are LLVM bitcode: archive them with the same LLVM version. [ ! -x /usr/bin/llvm-ar-$v ] || export AR=llvm-ar-$v RANLIB=llvm-ranlib-$v NM=llvm-nm-$v else export CC=clang CXX=clang++; fi ;; esac echo "== $($CXX --version | head -1)" meson setup builddir -Denable_app=disabled -Denable_tests=true >/dev/null || { echo "MATRIX build_rc=setup"; exit 1; } nice -n 19 ninja -C builddir -k 0 -j"$JOBS" b=$? echo "MATRIX build_rc=$b" [ "$b" = 0 ] || exit 1 [ "$TESTS" = 1 ] || exit 0 nice -n 19 meson test -C builddir --print-errorlogs --num-processes "$JOBS" t=$? echo "MATRIX test_rc=$t" exit "$t"' images_done=" " failed="" printf '%-13s %-6s %-6s %-6s %-4s %s\n' leg build errors tests min compiler | tee "$summary" for leg in $legs; do os=${leg%-*} compiler=${leg#*-} log="$out/$leg.log" case "$images_done" in *" $os "*) ;; *) echo "image $os ($(base_of "$os")) ..." >&2 refresh="" [ "${MATRIX_REFRESH:-0}" != 1 ] || refresh="--pull --no-cache" # shellcheck disable=SC2086 # $plat/$refresh are empty or flag words if ! nice -n 19 docker build -q $plat $refresh --build-arg "BASE=$(base_of "$os")" --build-arg "EXTRA_PKGS=$(extra_of "$os")" \ -f packaging/ci/Dockerfile.matrix -t "strawberry-matrix:$os" packaging/ci >/dev/null; then echo "image build failed for $os" >&2 failed="$failed $leg" continue fi images_done="$images_done$os " ;; esac echo "leg $leg ..." >&2 start=$(date +%s) # shellcheck disable=SC2086 nice -n 19 docker run --rm $plat --cpus="$cpus" --memory="$mem" \ -v "$PWD:/src:ro" -v "strawberry-matrix-ccache-$leg:/ccache" \ -e COMPILER="$compiler" -e JOBS="$jobs" -e TESTS="$tests" \ "strawberry-matrix:$os" bash -c "$LEG_SCRIPT" >"$log" 2>&1 || true min=$(( ($(date +%s) - start + 59) / 60 )) errors=$(grep -cE ': (fatal )?error: ' "$log" || true) build=FAIL grep -q '^MATRIX build_rc=0$' "$log" && build=ok if [ "$tests" != 1 ]; then t=skip elif grep -q '^MATRIX test_rc=0$' "$log"; then t=ok elif [ "$build" = ok ]; then t=FAIL else t=- fi printf '%-13s %-6s %-6s %-6s %-4s %s\n' "$leg" "$build" "$errors" "$t" "$min" \ "$(sed -n 's/^== //p' "$log" | head -1)" | tee -a "$summary" if [ "$build" != ok ] || [ "$t" = FAIL ]; then failed="$failed $leg"; fi done if [ -z "$failed" ]; then echo "compiler matrix: ALL PASSED ($summary)" exit 0 fi echo "compiler matrix: FAILED:$failed" >&2 for leg in $failed; do [ -f "$out/$leg.log" ] || continue echo "--- $leg ($out/$leg.log)" >&2 grep -m5 -E ': (fatal )?error: |^FAILED|[0-9]+/[0-9]+ .* FAIL ' "$out/$leg.log" >&2 || tail -5 "$out/$leg.log" >&2 done exit 1