Skip to content

CI: Add compiler caches to the native PR builds - #28

Merged
zackees merged 1 commit into
masterfrom
ci/compiler-cache
Oct 9, 2026
Merged

zackees merged 1 commit into
masterfrom
ci/compiler-cache

Conversation

@zackees

@zackees zackees commented Oct 9, 2026

Copy link
Copy Markdown
Member

Description

Adds a working compiler cache to every native build job in build-project.yaml, so a PR that touches C/C++ no longer recompiles OBS from scratch.

Job Before After
Windows x64 / arm64 none (10-14 min of MSBuild compiling) ccache 4.14.1 runs as cl.exe through MSBuild CLToolExe, using the existing ENABLE_CCACHE path in cmake/windows/compilerconfig.cmake
Ubuntu ccache with a fixed key, saved only on a miss, so it froze at its first save ccache keyed by commit, saved on master pushes
macOS Xcode CAS with the same fixed-key problem CAS keyed by commit; master pushes build cold so the saved CAS holds only what the current tree uses
Flatpak flatpak-builder --ccache, stored inside the dependency cache keyed by the manifest hash, so it was frozen too the .flatpak-builder/ccache directory gets its own commit-keyed cache, restored before the action

Why the Windows MSVC ccache path never worked: a later block in compilerconfig.cmake reset CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to ProgramDatabase (/Zi), and ccache refuses /Zi. While ccache is enabled the format now stays Embedded (/Z7). ccache handles /Fd and /MP without problems (see argprocessing.cpp in v4.14.1).

Why not zccache or sccache: neither can run as a cl.exe stand-in under the Visual Studio generator. On top of that, zccache 1.15.2 marks every MSVC compile that carries /Fd as non-cacheable (zccache-compiler/src/side_outputs.rs, from zccache#1175). CMake passes /Fd on every MSVC compile, under both the VS and Ninja generators, so zccache would cache nothing here.

Cache policy (zackees/ci.yml): PRs only restore. Only push to refs/heads/master saves. Only compiler-cache directories are cached, never build trees. Before saving, a master build runs ccache --evict-older-than <job age>, so each saved cache holds only the entries that build used.

Every job now writes ccache stats (hit rate and reasons for uncacheable compiles) to its log.

Motivation and Context

Windows x64 (about 15-16 min) is the critical path for native PRs. Measurements (cold PR run, master seed, warm follow-up PR) will be posted in the comments.

How Has This Been Tested?

./lint, ./unittest, and the local gate passed and stamped this commit. actionlint is clean except for the existing ubuntu-26.04 runner-label warnings.

Types of changes

  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Windows x64 and arm64 had no compiler cache, so every PR recompiled
OBS from scratch (10-14 min of MSBuild on the critical path). Enable
the ccache path OBS already has in cmake/windows/compilerconfig.cmake:
ccache 4.14.1 (pinned, SHA-256 checked) copied in as cl.exe and run
through MSBuild's CLToolExe. That path never worked because a later
block reset CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to ProgramDatabase
(/Zi), which ccache refuses; keep /Z7 while ccache is enabled.

zccache (soldr 0.9.31, zccache 1.15.2) and sccache were evaluated
first. Neither can stand in for cl.exe under the Visual Studio
generator, and zccache treats every compile with /Fd as non-cacheable
(zccache-compiler side_outputs.rs), which CMake passes on every MSVC
compile, so it would cache nothing even under Ninja.

The other jobs had caches that froze at their first save: Ubuntu
ccache and the macOS Xcode CAS used a fixed key and only saved on a
miss, and flatpak-builder's ccache lives in the dependency cache keyed
by the manifest hash. Key them by commit, save only on master pushes
(zackees/ci.yml), and prune ccache to the entries the master build used
so each saved cache stays the size of one build. Flatpak restores a
separate ccache directory before the action extracts its snapshot.
macOS master pushes build cold because the CAS cannot be pruned by age.

Log ccache stats (hit rate, uncacheable reasons) for Linux, Windows
and Flatpak so the hit rates are visible in the job logs.

Local-Gate: v1 tree=752e084324056aaf39f980541c2803b25cb2f14c secs=540 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791533188,"gate":"rust/all/fmt","host":"linux-x86_64","key":"816edad2ecc6b0b15e7802401af1fe8bb1d35a728c2d88ebc5588c39c5930c0e","lane":"lint","parents":["2c1f11b500123b80439308cb62535650ff57eeaa"],"secs":526,"stamp":"1f43395c228704774b36e73ad95c1226","tree":"752e084324056aaf39f980541c2803b25cb2f14c","v":1,"via":"run"}
Ci-Attestation: {"at":1791533188,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"816edad2ecc6b0b15e7802401af1fe8bb1d35a728c2d88ebc5588c39c5930c0e","lane":"lint","parents":["2c1f11b500123b80439308cb62535650ff57eeaa"],"secs":526,"stamp":"1a2830f57c23d6f863209e4cc887cac7","tree":"752e084324056aaf39f980541c2803b25cb2f14c","v":1,"via":"run"}
Ci-Attestation: {"at":1791533188,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a4d9714a127445dc789aacaf2a7fd67439fa91d3f98142f2fbfac6b1b2fdf370","lane":"rust-test","parents":["2c1f11b500123b80439308cb62535650ff57eeaa"],"secs":3,"stamp":"5049dec518d245aa5a21c7dd5b3979df","tree":"752e084324056aaf39f980541c2803b25cb2f14c","v":1,"via":"run"}
Ci-Attestation: {"at":1791533188,"gate":"general/linux-x64/tier2","host":"linux-x86_64","key":"c1e54f4ab167df63818b1e5d7f3563ad7c6d8fe4b75dcfa3be7d648488b054a9","lane":"tier2-linux","parents":["2c1f11b500123b80439308cb62535650ff57eeaa"],"secs":11,"stamp":"399202c98678f10246496abe72b5ad81","tree":"752e084324056aaf39f980541c2803b25cb2f14c","v":1,"via":"run"}
@zackees
zackees merged commit a15fda4 into master Oct 9, 2026
22 checks passed
@zackees
zackees deleted the ci/compiler-cache branch October 9, 2026 08:28
@zackees

zackees commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Measurements

  • Before: PR run 37897544153, no Windows cache.
  • Cold: this PR, run 37903089332. Windows caches empty; the other jobs restored the old fixed-key caches.
  • Warm: libobs: Spell top-level consistently in comments #31, run 37907490093. Changes a comment in libobs/obs-audio.c and restores the caches saved by master push run 37905200850.

Times are job wall time. The compile step is in parentheses (MSBuild Time Elapsed, the ninja span, or the Xcode build step).

Job Before Cold (this PR) Warm (#31) Warm hit rate
Windows x64 11.6 min (10:05) 18.4 min (16:47) 2.9 min (1:22) 715/717 (99.7%)
Windows arm64 16.3 min (14:21) 19.3 min (17:13) 3.5 min (1:31) 660/662 (99.7%)
Flatpak 10.9 min (5:17) 12.4 min (0:47) 11.7 min (0:56) see notes
macOS arm64 4.9 min 4.3 min 5.1 min (2:13) Xcode CAS
macOS x86_64 4.5 min 4.4 min 3.0 min (1:22) Xcode CAS
Ubuntu 3.2 min (0:58) 2.9 min (0:58) 3.5 min (0:51) 581/584 (99.5%)

On Windows, the 17 compiles ccache cannot cache are 15 "compiler output file missing" and 2 "could not use precompiled header".

Saved cache sizes after pruning to one build: Windows x64 299 MB, Windows arm64 285 MB, Ubuntu 150 MB, Xcode CAS 296 MB and 294 MB, Flatpak ccache 158 MB. A warm master push keeps the same sizes, so the pruning works. Repo cache usage is about 6.6 GB of the 10 GB limit, and 2.35 GB of that is the existing flatpak-builder dependency cache.

Notes:

  • Cold Windows builds are slower than before. MSBuild takes 16-17 min instead of 10-14 min, because MultiToolTask runs one cl per file and ccache and /Z7 add overhead. A PR that invalidates most objects, such as one that edits a widely included libobs header, pays that cost. Master pushes are warm after the first seed: Windows x64 took 4.1 min on master push 37908815453.
  • macOS master pushes now build cold by design (about 8 min of compiling, 11.5-12 min per job) so that the saved CAS does not grow without bound. PR builds restore it.
  • Flatpak's per-run hit rate cannot be isolated. The action's 2.35 GB snapshot restores ccache's stats files too, so the stats are cumulative. Compiling takes about 1 min warm. The rest of the job is not compiling: container start, the build-space cleanup (about 1.5 min), restoring the 2.35 GB dependency cache, and flatpak-builder's post-install, strip, debuginfo and ostree export (about 5 min). Flatpak is now the longest native job.
  • Ubuntu's ccache already worked. A cold Ubuntu build takes 11 min of ninja versus 51 s warm. It is now keyed by commit so it follows master.

icp4u pushed a commit to icp4u/obs-studio that referenced this pull request Oct 9, 2026
Comment-only change. It also serves as the warm-cache measurement for
the native CI compiler caches added in obs-rust#28.

Local-Gate: v1 tree=1e2d0b50af134d9d3371eaf70644f4c82b288f69 secs=22 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791534651,"gate":"rust/all/fmt","host":"linux-x86_64","key":"fd633a3887ad9584c2dc1d93873601315f68394be1156534f866b796bfae6334","lane":"lint","parents":["a15fda4045084da0b0aa8a8a79c921332a76abad"],"secs":9,"stamp":"23e742f11064a715a981be28fa8a6fc0","tree":"1e2d0b50af134d9d3371eaf70644f4c82b288f69","v":1,"via":"run"}
Ci-Attestation: {"at":1791534651,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"fd633a3887ad9584c2dc1d93873601315f68394be1156534f866b796bfae6334","lane":"lint","parents":["a15fda4045084da0b0aa8a8a79c921332a76abad"],"secs":9,"stamp":"c0843501afcf834f8cd5d3ef99acd7f4","tree":"1e2d0b50af134d9d3371eaf70644f4c82b288f69","v":1,"via":"run"}
Ci-Attestation: {"at":1791534651,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a340432c0fc182b243d058246468f322eccc5079cdda68c5bdf52620533476b1","lane":"rust-test","parents":["a15fda4045084da0b0aa8a8a79c921332a76abad"],"secs":3,"stamp":"eba36256d742720864d810c6d18555fd","tree":"1e2d0b50af134d9d3371eaf70644f4c82b288f69","v":1,"via":"run"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant