From 4dc2e1dd2269f2d25cb9242581dd8d5968e44d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20=C5=A0vagelj?= Date: Sun, 5 Jan 2025 05:15:54 +0100 Subject: [PATCH] Add sccache to all workflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tin Å vagelj --- .github/scripts/setup-sccache.sh | 70 +++++++++++++++++++++ .github/workflows/build-and-test-linux.yaml | 22 +------ .github/workflows/build-and-test-macos.yaml | 24 +++++-- .github/workflows/publish-appimage.yml | 19 ++++++ 4 files changed, 112 insertions(+), 23 deletions(-) create mode 100755 .github/scripts/setup-sccache.sh diff --git a/.github/scripts/setup-sccache.sh b/.github/scripts/setup-sccache.sh new file mode 100755 index 000000000..136c20c20 --- /dev/null +++ b/.github/scripts/setup-sccache.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +export SCCACHE_VERSION="${SCCACHE_VERSION:=0.9.0}" + +export sccache_arch="x86_64" +if [ "$RUNNER_ARCH" = "X86" ]; then + export sccache_arch="i686" +elif [ "$RUNNER_ARCH" = "X64" ]; then + export sccache_arch="x86_64" +elif [ "$RUNNER_ARCH" = "ARM" ]; then + export sccache_arch="armv7" +elif [ "$RUNNER_ARCH" = "ARM64" ]; then + export sccache_arch="aarm64" +fi + +install_sccache() { + export sccache_archive="sccache-v$SCCACHE_VERSION-$sccache_arch-$sccache_os" + export sccache_url="https://github.com/mozilla/sccache/releases/download/v$SCCACHE_VERSION/$sccache_archive.tar.gz" + + echo "Downloading $sccache_url..." + + if ! curl -s -L "$sccache_url" -o "$sccache_archive.tar.gz"; then + echo "Can't download $sccache_url.">2 + exit 1 + fi + if ! tar xz "$sccache_archive.tar.gz"; then + echo "Can't extract $sccache_archive.tar.gz">2 + exit 1 + fi + chmod +x "$sccache_archive/sccache" + sudo cp "$sccache_archive/sccache" "/bin/sccache" + rm -rf "$sccache_archive.tar.gz" + rm -rf "$sccache_archive" +} + +export sccache_os="unknown-linux-musl" +if [ "$RUNNER_OS" = "Linux" ]; then + export sccache_os="unknown-linux-musl" + if [ "$RUNNER_ARCH" = "ARM" ]; then + export sccache_os="unknown-linux-musleabi" + fi + if ! install_sccache; then + echo "Unable to install sccache!" >2 + exit 1 + fi +elif [ "$RUNNER_OS" = "macOS" ]; then + export sccache_os="apple-darwin" + if ! install_sccache; then + echo "Unable to install sccache!" >2 + exit 1 + fi +elif [ "$RUNNER_OS" = "Windows" ]; then + export sccache_os="pc-windows-msvc" + if ! install_sccache; then + echo "Unable to install sccache!" >2 + exit 1 + fi +fi + +echo "sccache installed." + +# Configure +mkdir $HOME/.sccache +echo "SCCACHE_DIR=$HOME/.sccache" >> $GITHUB_ENV +if [ "$RUNNER_DEBUG" = "1" ]; then + echo "Running with debug output; cached binary artifacts will be ignored to produce a cleaner build" + echo "SCCACHE_RECACHE=true" >> $GITHUB_ENV +fi + +echo "sccache configured." diff --git a/.github/workflows/build-and-test-linux.yaml b/.github/workflows/build-and-test-linux.yaml index 3793db7ff..8c58e149b 100644 --- a/.github/workflows/build-and-test-linux.yaml +++ b/.github/workflows/build-and-test-linux.yaml @@ -73,22 +73,6 @@ jobs: ncurses-dev \ ninja-build \ wayland-protocols - - name: Install sccache - working-directory: /home/runner - run: | - curl -s -L "https://github.com/mozilla/sccache/releases/download/v${{ env.SCCACHE_VERSION }}/sccache-v${{ env.SCCACHE_VERSION }}-x86_64-unknown-linux-musl.tar.gz" \ - | tar xz -C . - chmod +x "sccache-v${{ env.SCCACHE_VERSION }}-x86_64-unknown-linux-musl/sccache" - sudo cp "sccache-v${{ env.SCCACHE_VERSION }}-x86_64-unknown-linux-musl/sccache" "/bin/sccache" - rm -rf "sccache-v${{ env.SCCACHE_VERSION }}-x86_64-unknown-linux-musl" - mkdir .sccache - echo "SCCACHE_DIR=$PWD/.sccache" >> $GITHUB_ENV - echo "SCCACHE_COMPRESS=true" >> $GITHUB_ENV - echo "SCCACHE_COMPRESSLEVEL=7" >> $GITHUB_ENV - if [ "$RUNNER_DEBUG" = "1" ]; then - echo "Running with debug output; cached binary artifacts will be ignored to produce a cleaner build" - echo "SCCACHE_RECACHE=true" >> $GITHUB_ENV - fi - name: Install clang and libc++ if: matrix.compiler == 'clang' run: | @@ -104,6 +88,8 @@ jobs: g++ - name: Checkout uses: actions/checkout@v4 + - name: Install sccache + run: .github/scripts/setup-sccache.sh - name: Load cached compilation artifacts id: compiler-cache uses: actions/cache@v4 @@ -130,9 +116,7 @@ jobs: # Reset sccache statistics sccache --zero-stats - mkdir build - cd build - cmake .. -G Ninja \ + cmake . -B build -G Ninja \ -DBUILD_AUDACIOUS=ON \ -DBUILD_HTTP=ON \ -DBUILD_ICAL=ON \ diff --git a/.github/workflows/build-and-test-macos.yaml b/.github/workflows/build-and-test-macos.yaml index a5bc64308..d89de7b6a 100644 --- a/.github/workflows/build-and-test-macos.yaml +++ b/.github/workflows/build-and-test-macos.yaml @@ -16,6 +16,10 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + +env: + SCCACHE_VERSION: "0.9.0" + jobs: build: env: @@ -47,21 +51,33 @@ jobs: lua \ ninja \ pkg-config \ - sccache \ || true # Ignore errors - name: Checkout uses: actions/checkout@v4 - - run: mkdir build + - name: Configure sccache + run: .github/scripts/setup-sccache.sh + - name: Load cached compilation artifacts + id: compiler-cache + uses: actions/cache@v4 + with: + path: "${{ env.SCCACHE_DIR }}" + key: sccache-${{ matrix.os }}-${{ github.ref }}-${{ github.run_id }} + restore-keys: | + sccache-${{ matrix.os }}-${{ github.ref }} - name: Configure with CMake - working-directory: build run: | - cmake .. -G Ninja \ + # Reset sccache statistics + sccache --zero-stats + + cmake . -B build -G Ninja \ -DMAINTAINER_MODE=ON \ -DBUILD_WAYLAND=OFF \ -DBUILD_RSS=ON \ -DBUILD_CURL=ON - name: Compile run: cmake --build build + - name: Show sccache stats + run: sccache --show-stats - name: Test working-directory: build run: ctest --output-on-failure diff --git a/.github/workflows/publish-appimage.yml b/.github/workflows/publish-appimage.yml index 92d4360c5..8fdceb68c 100644 --- a/.github/workflows/publish-appimage.yml +++ b/.github/workflows/publish-appimage.yml @@ -16,6 +16,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +env: + SCCACHE_VERSION: "0.9.0" + jobs: build: runs-on: ${{ matrix.os }} @@ -106,10 +109,26 @@ jobs: libc++abi-${CLANG_VERSION}-dev echo "CC=clang-${CLANG_VERSION}" | tee -a $GITHUB_ENV echo "CXX=clang++-${CLANG_VERSION}" | tee -a $GITHUB_ENV + + - name: Install sccache + if: startsWith(github.ref, 'refs/tags/') != true + run: .github/scripts/setup-sccache.sh + - name: Load cached compilation artifacts + if: startsWith(github.ref, 'refs/tags/') != true + id: compiler-cache + uses: actions/cache@v4 + with: + path: "${{ env.SCCACHE_DIR }}" + key: sccache-${{ matrix.os }}-${{ matrix.arch }}-${{ github.ref }}-${{ github.run_id }} + restore-keys: | + sccache-${{ matrix.os }}-${{ matrix.arch }}-${{ github.ref }} - name: Build AppImage run: ./appimage/build.sh env: RELEASE: "${{ startsWith(github.ref, 'refs/tags/') && 'ON' || 'OFF' }}" + - name: Show sccache stats + if: startsWith(github.ref, 'refs/tags/') != true + run: sccache --show-stats - run: ./conky-x86_64.AppImage --version # print version - name: Set CONKY_VERSION run: echo "CONKY_VERSION=$(./conky-x86_64.AppImage --short-version)" | tee -a $GITHUB_ENV