Skip to content

fix(meson): move zccache wrapping to build.ninja post-patch (#2714) - #2811

Merged
zackees merged 2 commits into
masterfrom
fix/2714-zccache-build-ninja-patch
Jun 5, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/2714-zccache-build-ninja-patch

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #2714. The meson in-place reconfigure hangs / fails on Windows because the configure-phase compiler probe (<cc> -xc++ -E -v -) runs wrapped in zccache, which hangs >90s on some boxes (the bug reporter's environment included). Closes #2714.

Root cause

The meson native file emitted compiler entries of the form [zccache.exe, ctc-clang++.exe]. Meson's BinaryTable.parse_entry (mesonbuild/envconfig.py:465-470) only strips the literal strings ccache / sccache from the head of a compiler list, so the full-path zccache survived get_exelist(ccache=False) (compilers/mixins/gnu.py:401) and the probe ran wrapped. On the reporter's box (and reproduced here) that wrapped probe hung indefinitely instead of the bare compiler's <1s, producing No include directory found warnings followed by failing capability probes (Compiler does not support -std=c++11) and an aborted setup.

Full investigation: #2714 (comment)

Fix

Split configure-phase and build-phase responsibility:

  1. ci/meson/native_launchers.py - _resolve_fast_native_entries now emits the BARE ctc-clang / ctc-clang++ entries. The cache_binary parameter is removed. Meson sees what it can parse, so probes run natively.
  2. ci/meson/meson_markers.py - new inject_zccache_wrapping(build_dir, zccache_path) helper, sibling to the existing inject_ar_optimization_patches. After the setup step produces build.ninja, it rewrites the cpp_COMPILER, cpp_LINKER, c_COMPILER, c_LINKER rule command lines to prepend the zccache binary. STATIC_LINKER is intentionally excluded since it is already wrapped by ar_content_preserving.py. Idempotent, read-once / write-at-most-once, same pattern as the existing helper.
  3. ci/meson/meson_setup_execute.py - both call sites of inject_ar_optimization_patches (handle_skip_meson_setup and run_meson_setup_command) gain a paired inject_zccache_wrapping(build_dir, compiler.cache_binary) call.

Build-phase behaviour is unchanged: zccache still wraps every compile and link command. Only the configure-phase probes now run against the bare compiler. The existing zccache_version marker (build_config.py:279-299) continues to force reconfigure on zccache upgrades, which then re-runs the post-patch with the new path.

Files touched

 ci/meson/meson_markers.py           | 86 +++++++++++++++++++++++++++++++++++++
 ci/meson/meson_setup_execute.py     | 14 +++++-
 ci/meson/native_launchers.py        | 30 ++++++-------
 3 files changed, 113 insertions(+), 17 deletions(-)

Before / after (Windows 10, bug reporter's environment)

Phase Before After
Configure probe <cc> -xc++ -E -v - hangs >90s, killed <1s (bare ctc-clang++.exe)
Configure phase total aborts with C++ Compiler does not support -std=c++11 0.78s, -std=c++11: YES
In-place reconfigure on test-file change (the exact bug scenario) fails 1.13s configure, full run 50s, 309/309 pass
build.ninja cpp_COMPILER rule unchanged zccache wrapping applied via post-patch

Note: the bug reporter's box also has a separate pre-existing zccache-daemon-health issue (daemon-side recv timed out after 300s for every compile) that is independent of this fix. Verification above was performed with FASTLED_DOCKER=1 to bypass zccache and isolate the configure-phase fix; the configure phase itself works identically with and without zccache.

Test plan

  • Wipe .build/meson-quick, run bash test --cpp - configure completes <1s, full run 50s, 309/309 pass
  • Modify a test-file content (the bug-triggering scenario per the original report) and re-run bash test --cpp - the build system auto-detects test changes, reconfigures in 1.13s, then 309/309 pass
  • Inspect generated build.ninja - cpp_COMPILER and cpp_LINKER rules carry zccache.exe prefix; STATIC_LINKER retains its ar_content_preserving.py wrapper untouched
  • Inspect meson-log.txt - no No include directory found warnings; -std=c++11: YES
  • bash lint passes
  • CI verification - Linux / macOS builds (this fix is platform-agnostic; the zccache wrapping path is shared)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved Meson build integration to apply compiler-caching wrapping to generated build files after setup, and to resolve native launcher entries against the bare toolchain so configure probes run correctly.
  • Bug Fixes
    • Prevented double-wrapping of cache paths across platforms and emit warnings when cache wrapping cannot be applied.

…2714)

The meson native file previously emitted compiler entries of the form
``[zccache.exe, ctc-clang++.exe]``. Meson's ``BinaryTable.parse_entry``
only strips the literal strings ``ccache``/``sccache`` from the head of
a compiler list (``mesonbuild/envconfig.py:465-470``), so the
full-path zccache survived ``get_exelist(ccache=False)`` and the
configure-phase include-dir probe (``<cc> -xc++ -E -v -``) ran wrapped
in zccache. On the bug reporter's box that probe hung >90s instead of
the bare compiler's <1s, producing "No include directory found"
warnings followed by failing capability probes ("does not support
-std=c++11").

This change splits responsibility:

* ``_resolve_fast_native_entries`` (``ci/meson/native_launchers.py``)
  now emits the BARE ctc-clang/ctc-clang++ entries. The
  ``cache_binary`` parameter is removed.

* New ``inject_zccache_wrapping`` in ``ci/meson/meson_markers.py`` is
  a sibling to the existing ``inject_ar_optimization_patches``. After
  ``meson setup`` produces ``build.ninja``, it rewrites the
  ``cpp_COMPILER``, ``cpp_LINKER``, ``c_COMPILER``, ``c_LINKER`` rule
  command lines to prepend the zccache binary. STATIC_LINKER is
  excluded since it is already wrapped by ``ar_content_preserving.py``.

* Both call sites of ``inject_ar_optimization_patches`` in
  ``ci/meson/meson_setup_execute.py`` (``handle_skip_meson_setup``
  and ``run_meson_setup_command``) gain a paired
  ``inject_zccache_wrapping`` call.

The build phase still goes through zccache exactly as before. Only the
configure phase now sees the bare compiler. Cache-version
invalidation continues to work via the existing ``zccache_version``
marker.

Verified on Windows 10:

* Configure phase: <1s (was hanging >90s before this fix).
* meson-log.txt reports ``-std=c++11: YES`` with no
  "No include directory found" warnings.
* In-place reconfigure triggered by a test-file content change
  completes in ~1.1s for the configure phase.
* Full ``bash test --cpp`` passes 309/309 in ~50s on a warm cache.
* Generated ``build.ninja`` shows zccache wrapping on
  ``cpp_COMPILER``/``cpp_LINKER`` rules so build-phase caching is
  preserved.

Investigation:
#2714 (comment)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7f818a86-0ef2-4d0c-b6e6-0d73e43ab114

📥 Commits

Reviewing files that changed from the base of the PR and between ad41e9f and a2f2004.

📒 Files selected for processing (3)
  • ci/meson/meson_markers.py
  • ci/meson/meson_setup_execute.py
  • ci/meson/native_launchers.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • ci/meson/meson_markers.py
  • ci/meson/native_launchers.py
  • ci/meson/meson_setup_execute.py

📝 Walkthrough

Walkthrough

This PR relocates zccache integration from native launcher resolution to post-setup build.ninja injection. It introduces build.ninja wrapping logic, refactors native launcher resolution to remove cache binary composition, and orchestrates zccache injection across both meson setup paths.

Changes

Zccache architecture refactoring

Layer / File(s) Summary
Build.ninja zccache wrapping mechanism
ci/meson/meson_markers.py
Introduces _ZCCACHE_TARGET_RULES constant enumerating compile/link Meson rules and inject_zccache_wrapping() which reads build.ninja, locates rule command = lines, and prepends the quoted zccache binary path if not already present, with idempotent write semantics.
Native launcher resolution without cache
ci/meson/native_launchers.py
Refactors _resolve_fast_native_entries() to remove the cache_binary parameter and return bare ctc-clang/ctc-clang++ launcher paths only; docstring now defers zccache integration to later build.ninja injection.
Meson setup and zccache wrapping orchestration
ci/meson/meson_setup_execute.py
Imports inject_zccache_wrapping, updates write_meson_native_file to resolve bare launchers without cache prefix, and calls zccache wrapping after meson setup completes in both skip-setup and normal configuration paths, warning to stderr on failure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2761: Also modifies meson setup flow and zccache integration; related changes around deferring or altering zccache usage during Meson setup.

Poem

🐰
I nibble paths and hop through files,
Bare compilers first, no cachey wiles,
Then ninja wakes and rules I trace,
I tuck zccache in each command's space,
Builds scurry faster, carrots near—hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: moving zccache wrapping from the native file (configure phase) to a post-patch operation on build.ninja (build phase), which directly addresses the root cause of the issue.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2714-zccache-build-ninja-patch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
ci/meson/meson_setup_execute.py (1)

328-328: ⚡ Quick win

Consider checking return value from inject_zccache_wrapping for observability.

Both call sites invoke inject_zccache_wrapping() but don't check the return value. The function returns False when injection fails due to I/O errors or missing build.ninja, meaning the build would continue with unwrapped compiler commands (no caching). This failure mode is currently silent.

While consistent with the existing pattern for inject_ar_optimization_patches() (lines 327, 639), logging injection failures would improve observability—especially since zccache is expected when compiler.cache_binary is set.

📊 Suggested observability improvement
-    inject_zccache_wrapping(build_dir, compiler.cache_binary)
+    if compiler.cache_binary and not inject_zccache_wrapping(build_dir, compiler.cache_binary):
+        _ts_print("[MESON] Warning: Failed to inject zccache wrapping into build.ninja")

Apply to both call sites (lines 328 and 640).

Also applies to: 640-640

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/meson/meson_setup_execute.py` at line 328, Call-site should check
inject_zccache_wrapping(build_dir, compiler.cache_binary) return and log
failures for observability; specifically, after calling inject_zccache_wrapping
in the functions that also call inject_ar_optimization_patches, examine its
boolean result and emit a clear warning/error via the existing logger when it
returns False (include build_dir and compiler.cache_binary context), so a failed
injection due to I/O or missing build.ninja is visible instead of silently
continuing.
ci/meson/native_launchers.py (1)

337-341: 💤 Low value

Consider escaping single quotes in path formatting for Meson native file.

The paths are formatted as single-quoted strings within list notation (e.g., ['‌/path/to/ctc-clang']) without escaping single quotes. While extremely rare in practice—especially for paths in .cached/clang-native/—a path containing a single quote would produce malformed Meson list syntax.

🛡️ Optional defensive escaping
         return FastNativeEntries(
-            cc=f"['{ctc_c}']",
-            cxx=f"['{ctc_cpp}']",
+            cc=f"['{ctc_c.replace(chr(39), chr(92) + chr(39))}']",
+            cxx=f"['{ctc_cpp.replace(chr(39), chr(92) + chr(39))}']",
             ar=f"['{ar_path}']",
         )

Alternatively, consider using Python's shlex.quote() or Meson's native list-of-strings format instead of manually constructing quoted strings.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/meson/native_launchers.py` around lines 337 - 341, The Meson string
construction uses f"['{ctc_c}']" (and similar for ctc_cpp and ar_path) which
breaks if a path contains a single quote; update the return of FastNativeEntries
to safely quote/escape each path (ctc_c, ctc_cpp, ar_path) before embedding into
the "['...']" string—e.g., import shlex and use shlex.quote(ctc_c),
shlex.quote(ctc_cpp), shlex.quote(ar_path) (or explicitly replace single quotes
with escaped versions) so the generated Meson list-of-strings remains valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/meson/meson_markers.py`:
- Around line 322-325: The try/except blocks that call
build_ninja_path.read_text(...) and the corresponding write block
(build_ninja_path.write_text(...)) must handle KeyboardInterrupt before OSError;
update each block to first catch KeyboardInterrupt and invoke
handle_keyboard_interrupt() (or re-raise) and then catch OSError to return False
or handle the error; ensure you reference the existing symbols
build_ninja_path.read_text and build_ninja_path.write_text and call
handle_keyboard_interrupt() in the KeyboardInterrupt except branch while leaving
the OSError handling intact.
- Around line 327-355: The idempotency check fails on Windows because
zccache_path may contain backslashes while Meson uses forward slashes; normalize
zccache_path to use forward slashes before building zccache_quoted and
performing the startswith check. In practice, transform
zccache_path.replace("\\", "/") (or Path.as_posix()) and then set zccache_quoted
= f'"{normalized_path}"' so the existing_value.startswith(zccache_quoted + " ")
comparison (and the string inserted into new_content) use the same normalized
separator style; update references to zccache_path when constructing
zccache_quoted and doing the idempotency check in the loop over
_ZCCACHE_TARGET_RULES and existing_value.

---

Nitpick comments:
In `@ci/meson/meson_setup_execute.py`:
- Line 328: Call-site should check inject_zccache_wrapping(build_dir,
compiler.cache_binary) return and log failures for observability; specifically,
after calling inject_zccache_wrapping in the functions that also call
inject_ar_optimization_patches, examine its boolean result and emit a clear
warning/error via the existing logger when it returns False (include build_dir
and compiler.cache_binary context), so a failed injection due to I/O or missing
build.ninja is visible instead of silently continuing.

In `@ci/meson/native_launchers.py`:
- Around line 337-341: The Meson string construction uses f"['{ctc_c}']" (and
similar for ctc_cpp and ar_path) which breaks if a path contains a single quote;
update the return of FastNativeEntries to safely quote/escape each path (ctc_c,
ctc_cpp, ar_path) before embedding into the "['...']" string—e.g., import shlex
and use shlex.quote(ctc_c), shlex.quote(ctc_cpp), shlex.quote(ar_path) (or
explicitly replace single quotes with escaped versions) so the generated Meson
list-of-strings remains valid.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b7df5355-9878-459d-8a94-11afb23e2eb2

📥 Commits

Reviewing files that changed from the base of the PR and between 787de45 and ad41e9f.

📒 Files selected for processing (3)
  • ci/meson/meson_markers.py
  • ci/meson/meson_setup_execute.py
  • ci/meson/native_launchers.py

Comment thread ci/meson/meson_markers.py Resolved
Comment thread ci/meson/meson_markers.py Resolved
Addresses all four findings from the CodeRabbit review:

1. KeyboardInterrupt before OSError in inject_zccache_wrapping
   (meson_markers.py read+write blocks). Both blocks now catch
   KeyboardInterrupt first, invoke handle_keyboard_interrupt(),
   and re-raise -- matching the policy already enforced elsewhere
   in ci/meson and documented in agents/docs/python-standards.md.

2. Path-separator normalization for Windows idempotency
   (meson_markers.py). _find_zccache_binary() returns paths with
   backslashes on Windows, but meson emits forward slashes in
   build.ninja. Without normalization the startswith() idempotency
   check would miss its own prior injection and double-wrap on the
   second invocation. Verified by re-injecting with a backslashed
   input path on a build.ninja produced by the forward-slashed first
   injection -- the count stays at 2 wrappings.

3. Observable failure of inject_zccache_wrapping
   (meson_setup_execute.py, both call sites). Each call now checks
   the return value and emits a warning to stderr when injection
   fails with cache_binary configured, so a silent fall-through to
   an unwrapped (no-caching) build no longer goes unnoticed.

4. Defensive single-quote escaping in fast native-file entries
   (native_launchers.py). The generated meson list-of-strings now
   escapes any embedded single quote. Paths under .cached/clang-native/
   never contain a quote in practice, but the escaping costs nothing
   and prevents a hard-to-debug parse failure in pathological setups.

Verification:
- bash lint passes
- inject_zccache_wrapping smoke test confirms idempotency on Windows
  with a backslashed input path
- the configure phase fix for #2714 continues to hold

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees

zackees commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai All four review findings addressed in a2f2004.

Actionable (2):

  1. meson_markers.py — KeyboardInterrupt before OSError (critical, lines 322-325 & 360-363): both try/except blocks now catch KeyboardInterrupt first, invoke handle_keyboard_interrupt(), and re-raise. Reply on the inline thread.

  2. meson_markers.py — Windows path-separator normalization (major, lines 327-355): zccache_path is now normalized to forward slashes before constructing zccache_quoted and before the startswith idempotency check. Verified that calling inject_zccache_wrapping a second time with a backslashed Windows path on a build.ninja that was already wrapped via the forward-slashed first injection produces no double-wrap (count stays at 2). Reply on the inline thread.

Nitpicks (2) — both applied:

  1. meson_setup_execute.py — Observability on injection failure (lines 328, 640): both call sites now check inject_zccache_wrapping's return value and emit a [MESON] Warning to stderr when injection fails with compiler.cache_binary configured, so a silent fall-through to an unwrapped (no-caching) build no longer goes unnoticed.

  2. native_launchers.py — Defensive single-quote escaping (lines 337-341): paths emitted into the Meson list-of-strings (['...']) now escape any embedded single quote via a local helper. Paths under .cached/clang-native/ never contain a quote in practice, but the escaping costs nothing and prevents a hard-to-debug parse failure in pathological setups.

Verification: bash lint passes; the configure-phase fix for #2714 continues to hold (the only test failures encountered locally were pre-existing compilation errors stemming from cached cross-worktree includes, unrelated to this change).

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@zackees: All four fixes confirmed — thank you for the thorough summary!

Quick recap:

  1. KeyboardInterrupt before OSError — Both try/except blocks in inject_zccache_wrapping now correctly prioritize KeyboardInterrupt, invoke handle_keyboard_interrupt(), and re-raise. ✅
  2. Windows path-separator normalization — zccache_path is normalized to forward slashes before both the quoted-string construction and the idempotency startswith check, with the double-wrap protection verified. ✅
  3. Observability on injection failure — Both call sites in meson_setup_execute.py now emit a [MESON] Warning to stderr when inject_zccache_wrapping returns False with a cache_binary configured. ✅
  4. Defensive single-quote escaping — Paths emitted into Meson's list-of-strings format are now sanitized against embedded single quotes. ✅

The implementation looks solid.

🐇 ✨


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@zackees
zackees merged commit 2436493 into master Jun 5, 2026
15 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
@zackees
zackees deleted the fix/2714-zccache-build-ninja-patch branch June 5, 2026 15:54
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.

Meson in-place reconfigure fails C++11 probe after test-discovery cache invalidation

1 participant