diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0554a58..70318de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,10 @@ jobs: build: name: Build (${{ matrix.os }}) runs-on: ${{ matrix.os }} + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 200M + CCACHE_COMPILERCHECK: content strategy: fail-fast: false matrix: @@ -23,7 +27,26 @@ jobs: sudo apt-get update -qq sudo apt-get install -y \ build-essential cmake pkg-config \ - libusb-1.0-0-dev libjpeg-dev + libusb-1.0-0-dev libjpeg-dev ccache + + - name: Record compiler identity + id: compiler + run: | + fingerprint="$({ cc --version; c++ --version; } | sha256sum | cut -d' ' -f1)" + echo "fingerprint=$fingerprint" >> "$GITHUB_OUTPUT" + + - name: Cache ccache + uses: actions/cache@v6 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.os }}-${{ steps.compiler.outputs.fingerprint }}-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'include/**', 'src/**', '.github/workflows/build.yml') }} + restore-keys: | + ccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.os }}-${{ steps.compiler.outputs.fingerprint }}- + + - name: Configure bounded ccache + run: | + ccache -M "$CCACHE_MAXSIZE" + ccache --zero-stats - name: Configure (auto-detach ON) run: | @@ -32,7 +55,9 @@ jobs: -DBUILD_SHARED_LIBS=ON \ -DBUILD_EXAMPLE=OFF \ -DBUILD_TEST=OFF \ - -DLIBUVC_AUTO_DETACH_KERNEL_DRIVER=ON + -DLIBUVC_AUTO_DETACH_KERNEL_DRIVER=ON \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: Build run: cmake --build build --parallel @@ -55,7 +80,9 @@ jobs: -DBUILD_SHARED_LIBS=ON \ -DBUILD_EXAMPLE=OFF \ -DBUILD_TEST=OFF \ - -DLIBUVC_AUTO_DETACH_KERNEL_DRIVER=OFF + -DLIBUVC_AUTO_DETACH_KERNEL_DRIVER=OFF \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache cmake --build build-off --parallel echo "PASS: OFF variant builds cleanly" @@ -65,3 +92,11 @@ jobs: echo "PASS: shared library produced" test -f build/libuvc.a echo "PASS: static library produced" + + - name: Show ccache statistics + if: ${{ always() }} + run: ccache --show-stats + + - name: Enforce ccache bound + if: ${{ always() }} + run: ccache -c diff --git a/README.md b/README.md index 189c29b..cbe869a 100644 --- a/README.md +++ b/README.md @@ -56,4 +56,14 @@ Then you can start them with `./example` and `./uvc_test` respectively. Note tha The documentation for `libuvc` can currently be found at https://libuvc.github.io/. +The GitHub Actions build check uses a bounded compiler cache for both CMake build +variants. It caches only the workspace-local `.ccache` directory, keyed by the +runner, compiler identity, and source/build workflow inputs; the `build/` and +`build-off/` directories are never cached. Local builds do not require ccache, but +you can enable it with CMake's compiler launcher options: + + cmake -B build \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + Happy hacking!