Skip to content

ci: enable ccache persistence across CI workflow runs - #20580

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:ci/enable-ccache
Oct 12, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:ci/enable-ccache

Conversation

@Swatantra-66

@Swatantra-66 Swatantra-66 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Following the discussion in #20483 with @acassis and the suggestion from @casaroli, this PR implements the first phase of CI optimization: enabling persistent ccache caching across GitHub Actions workflow runs.

Background & Problem

In .github/workflows/build.yml, Linux matrix jobs already pass -c to ./cibuild.sh, which configures ccache wrappers and tools inside the ghcr.io/apache/nuttx/apache-nuttx-ci-linux Docker container. However, because GitHub Actions did not configure actions/cache for the ccache directory (sources/tools/ccache), the entire cache was destroyed upon container teardown. As a result, every CI job compiled from scratch with an empty cache.

Key Changes

  1. GitHub Actions Cache Integration:
    • Added actions/cache@v6 in .github/workflows/build.yml for each board matrix job (sources/tools/ccache).
    • Keyed per board matrix: ${{ runner.os }}-${{ matrix.boards }}-ccache-${{ github.sha }} with fallback restore-keys: ${{ runner.os }}-${{ matrix.boards }}-ccache- so matrix partitions (e.g. arm-01, risc-v-01, sim-01) maintain isolated, non-conflicting compiler caches.
  2. Container Permission Adjustment:
    • Added a post-build step (sudo chmod -R a+rwX sources/tools/ccache) with if: always() so the non-root runner user can archive Docker-created cache directories without permission errors.
  3. Repository Cache Quota Protection:
    • Configured export CCACHE_MAXSIZE="${CCACHE_MAXSIZE:-1G}" in tools/ci/cibuild.sh to cap disk usage per matrix job, preventing eviction from GitHub's 10GB repository cache limit.
  4. Environment Path Fix:
    • Added add_path "${NUTTXTOOLS}"/ccache/bin in tools/ci/platforms/ubuntu.sh for parity with msys2.sh.

Addresses #20483 (Phase 1).

Impact

  • Build Process: Substantially reduces compilation times for re-runs, sequential PR commits, and architecture rebuilds by reusing cached object files.
  • Resource Utilization: Bounded to 1GB per matrix partition to stay well within GitHub Actions repository storage quotas.
  • Compatibility: Completely non-breaking; fallback behavior maintains clean builds on cache misses.

Testing

  • Host: Windows 11 / Git Bash
  • Verified script syntax and toolchain wrappers locally with tools/checkpatch.sh (0 warnings, 0 errors).
  • Validated YAML schema and indentation in .github/workflows/build.yml.
  • Verified directory path resolution: CIWORKSPACE (/github/workspace/sources) inside Docker maps directly to host runner path sources/tools/ccache.

@github-actions github-actions Bot added Area: CI Size: S The size of the change in this PR is small labels Oct 10, 2026
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report

qemu-intel64

Currently, Linux matrix jobs in .github/workflows/build.yml pass '-c' to cibuild.sh to enable ccache inside the Docker container, but the cache directory (sources/tools/ccache) is discarded upon container exit and runner teardown.

This change enables persistent ccache caching across GitHub Actions workflow runs:
1. Add an actions/cache@v6 step in build.yml to restore and save sources/tools/ccache per board matrix job.
2. Add a post-build permission adjustment step so the runner user can archive Docker-created cache files without permission issues.
3. Configure CCACHE_MAXSIZE (defaulting to 1G per board matrix job) in cibuild.sh to prevent unbounded repository cache consumption.
4. Add the ccache wrapper directory to PATH in tools/ci/platforms/ubuntu.sh.

Addresses apache#20483.

Signed-off-by: Swatantra Yadav <maverickswatantra@gmail.com>
@xiaoxiang781216
xiaoxiang781216 merged commit 1a2d22e into apache:master Oct 12, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: CI Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants