From 59f04853c8e233120274bf4f7e3ac4a83268fd4c Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 17 Apr 2025 22:41:50 +0000 Subject: [PATCH 1/4] CI: Build for Gentoo --- .github/workflows/build.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0e29f56..e40500c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,6 +22,7 @@ jobs: - oraclelinux:9 - archlinux:latest - clearlinux:latest + - gentoo/stage3:hardened config: - cmake_args: "-DENABLE_API=ON -DCMAKE_C_COMPILER=gcc" - cmake_args: "-DENABLE_API=ON -DCMAKE_C_COMPILER=clang" @@ -69,6 +70,20 @@ jobs: PACKAGES_CLANG="llvm" PACKAGES_GCC='' # included in c-basic ;; + gentoo/*) + INIT_CMD=' + emerge --sync --quiet + ' + INSTALL_CMD="emerge -1 sec-keys/openpgp-keys-gentoo-release && getuto && cat /etc/portage/make.conf && USE='-perl -extra -static-analyzer -compiler-rt -openmp -sanitize -adns -alt-svc -ftp -hsts -http2 -http3 -imap -pop3 -progress-meter -psl -quic -curl_quic_openssl -smtp -tftp -websockets -nls' emerge -vuDtkg1 --noreplace --jobs=\$(nproc) --buildpkg" + PACKAGES="dev-vcs/git dev-build/cmake net-misc/curl dev-libs/jansson dev-libs/libsodium virtual/pkgconfig" + PACKAGES_API="net-libs/libmicrohttpd" + PACKAGES_CLANG="llvm-core/clang" + POSTINSTALL_CMD=' + set +ex + source /etc/profile + set -ex + ' + ;; esac PACKAGES="$PACKAGES ${{ matrix.config.extra_deps }}" if [[ "${{ matrix.config.cmake_args }}" =~ ENABLE_API=ON ]]; then @@ -80,7 +95,9 @@ jobs: PACKAGES="$PACKAGES $PACKAGES_CLANG" fi CMD="set -ex + ${INIT_CMD} ${INSTALL_CMD} ${PACKAGES} + ${POSTINSTALL_CMD} git config --global --add safe.directory /workspace mkdir -p build cd build From 7e9a02a4b30c7e8ec5d88a7f3ff7f59e3e7b25eb Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 18 Apr 2025 00:32:30 +0000 Subject: [PATCH 2/4] CI: Cache binpkgs for Gentoo --- .github/workflows/build.yaml | 55 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e40500c..e0b341b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -39,8 +39,19 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Restore package cache + if: startsWith(matrix.os, 'gentoo/') + uses: actions/cache/restore@v4 + with: + path: pkg-cache + key: never-exists + restore-keys: | + ${{ matrix.os }}-pkg-cache- + - name: Build inside Docker + id: docker-build run: | + PKG_CACHE_DIR=/pkg-cache PACKAGES_CLANG='clang' PACKAGES_GCC='gcc' case "${{ matrix.os }}" in @@ -71,11 +82,25 @@ jobs: PACKAGES_GCC='' # included in c-basic ;; gentoo/*) + PKG_CACHE_DIR='/var/cache/binpkgs' INIT_CMD=' - emerge --sync --quiet + if [ -e /var/cache/binpkgs/gentoo-repo.txz ]; then + rm -rf /var/db/repos/gentoo + tar -C /var/db/repos -xpf /var/cache/binpkgs/gentoo-repo.txz + rm /var/cache/binpkgs/gentoo-repo.txz + + cache_cksum() { + find /var/db/repos/gentoo /var/cache/binpkgs -type f -print0 | sort -z | xargs -0 sha256sum + } + cache_cksum > /tmp/initial-pkg-cache.cksum + + emerge --sync --quiet || true # can fail if cache is recent enough + else + emerge --sync --quiet + fi ' INSTALL_CMD="emerge -1 sec-keys/openpgp-keys-gentoo-release && getuto && cat /etc/portage/make.conf && USE='-perl -extra -static-analyzer -compiler-rt -openmp -sanitize -adns -alt-svc -ftp -hsts -http2 -http3 -imap -pop3 -progress-meter -psl -quic -curl_quic_openssl -smtp -tftp -websockets -nls' emerge -vuDtkg1 --noreplace --jobs=\$(nproc) --buildpkg" - PACKAGES="dev-vcs/git dev-build/cmake net-misc/curl dev-libs/jansson dev-libs/libsodium virtual/pkgconfig" + PACKAGES="dev-vcs/git dev-build/cmake net-misc/curl dev-libs/jansson dev-libs/libsodium virtual/pkgconfig app-portage/gentoolkit" PACKAGES_API="net-libs/libmicrohttpd" PACKAGES_CLANG="llvm-core/clang" POSTINSTALL_CMD=' @@ -83,6 +108,16 @@ jobs: source /etc/profile set -ex ' + CLEANUP_CMD=' + if ls -d /var/db/pkg/llvm-core/clang-*; then + [ -e /tmp/initial-pkg-cache.cksum ] && cache_cksum >/tmp/final-pkg-cache.cksum + if ! diff -u /tmp/{initial,final}-pkg-cache.cksum; then + ( cd /var/db/repos && tar --sort=name -cpJf /var/cache/binpkgs/gentoo-repo.txz gentoo ) + touch /output/SAVE_CACHE + eclean -t 2w packages --changed-deps + fi + fi + ' ;; esac PACKAGES="$PACKAGES ${{ matrix.config.extra_deps }}" @@ -104,8 +139,24 @@ jobs: cmake /workspace -DCMAKE_C_FLAGS='-Wall -Werror' ${{ matrix.config.cmake_args }} make -j\$(nproc) ./datum_gateway --help + ${CLEANUP_CMD} " docker run \ + -v ./pkg-cache:"${PKG_CACHE_DIR}" \ + -v ./output:"/output" \ -v "${{ github.workspace }}:/workspace":ro \ "${{ matrix.os }}" \ /bin/sh -c "${CMD}" + + if [ -e output/SAVE_CACHE ]; then + echo 'save_cache=true' >> "$GITHUB_OUTPUT" + else + echo 'save_cache=false' >> "$GITHUB_OUTPUT" + fi + + - name: Save package cache + if: steps.docker-build.outputs.save_cache == 'true' + uses: actions/cache/save@v4 + with: + path: pkg-cache + key: ${{ matrix.os }}-pkg-cache-${{ github.sha }} From 30b202305997fd4653b089eb61e25a78d11b7b1a Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 17 Apr 2025 00:09:58 +0000 Subject: [PATCH 3/4] CI: Build for Alpine --- .github/workflows/build.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e0b341b..fbd8cbc 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,6 +20,7 @@ jobs: - amazonlinux:latest - fedora:latest - oraclelinux:9 + - alpine:latest - archlinux:latest - clearlinux:latest - gentoo/stage3:hardened @@ -69,6 +70,11 @@ jobs: PACKAGES_API="libmicrohttpd-devel" [[ "${{ matrix.config.cmake_args }}" =~ clang|gcc ]] || PACKAGES="$PACKAGES gcc" ;; + alpine:*) + INSTALL_CMD="apk add --no-cache" + PACKAGES="git build-base cmake argp-standalone curl-dev jansson-dev libsodium-dev" + PACKAGES_API="libmicrohttpd-dev" + ;; archlinux:*) INSTALL_CMD="pacman -Syu --noconfirm" PACKAGES="git base-devel cmake curl jansson libsodium" From 3af3f747de3c72e94e78e5548e122d4d3a64785a Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 17 Apr 2025 22:41:50 +0000 Subject: [PATCH 4/4] CI: Build for Gentoo musl --- .github/workflows/build.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fbd8cbc..39dcc3c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,6 +23,7 @@ jobs: - alpine:latest - archlinux:latest - clearlinux:latest + - gentoo/stage3:musl-hardened - gentoo/stage3:hardened config: - cmake_args: "-DENABLE_API=ON -DCMAKE_C_COMPILER=gcc" @@ -107,6 +108,7 @@ jobs: ' INSTALL_CMD="emerge -1 sec-keys/openpgp-keys-gentoo-release && getuto && cat /etc/portage/make.conf && USE='-perl -extra -static-analyzer -compiler-rt -openmp -sanitize -adns -alt-svc -ftp -hsts -http2 -http3 -imap -pop3 -progress-meter -psl -quic -curl_quic_openssl -smtp -tftp -websockets -nls' emerge -vuDtkg1 --noreplace --jobs=\$(nproc) --buildpkg" PACKAGES="dev-vcs/git dev-build/cmake net-misc/curl dev-libs/jansson dev-libs/libsodium virtual/pkgconfig app-portage/gentoolkit" + [[ "${{ matrix.os }}" =~ musl ]] && PACKAGES="$PACKAGES sys-libs/argp-standalone" PACKAGES_API="net-libs/libmicrohttpd" PACKAGES_CLANG="llvm-core/clang" POSTINSTALL_CMD='