Skip to content

build: normalize zccache compile paths#193

Merged
zackees merged 2 commits intomainfrom
fix/zccache-canonical-workspace-paths
Apr 23, 2026
Merged

build: normalize zccache compile paths#193
zackees merged 2 commits intomainfrom
fix/zccache-canonical-workspace-paths

Conversation

@zackees
Copy link
Copy Markdown
Member

@zackees zackees commented Apr 23, 2026

Summary

  • canonicalize the inferred zccache compile CWD when the workspace exists
  • rewrite source/output and common path-bearing compiler flags relative to that CWD before wrapping with zccache
  • update the workspace-rename integration test for canonical child CWD reporting on macOS and Windows

Investigation

The failing run was https://github.com/FastLED/fbuild/actions/runs/24805459290. The macOS test failed because the runner temp path was created as /var/..., but the child process reported its CWD as /private/var/.... The fake zccache wrapper then received absolute source/include args with the non-canonical spelling and could not relativize them against the canonical CWD, producing two different cache keys.

This belongs in fbuild: once fbuild chooses a zccache CWD, it should pass zccache path arguments that are stable relative to that CWD. No upstream zccache issue filed.

Testing

  • uv run soldr cargo fmt --all -- --check
  • uv run soldr cargo check -p fbuild-build
  • uv run soldr cargo clippy -p fbuild-build -- -D warnings
  • uv run soldr cargo test -p fbuild-build
  • uv run soldr cargo test -p fbuild-build --test zccache_hit_across_workspace_rename
  • uv run soldr cargo test -p fbuild-build zccache::tests::

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved build cache effectiveness when working with renamed or relocated workspace directories.
  • Chores

    • Optimized internal path and compiler flag normalization for more reliable cache behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@zackees has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 48 minutes and 21 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 48 minutes and 21 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a52bea11-5cad-4d72-b5d1-3efd08b808af

📥 Commits

Reviewing files that changed from the base of the PR and between 11fd09f and f9b85e0.

📒 Files selected for processing (1)
  • .github/workflows/template_build.yml
📝 Walkthrough

Walkthrough

Updates zccache module to canonicalize workspace paths and introduces utilities for rewriting compiler arguments and paths relative to computed compile working directories. Integrates these utilities into the compilation flow to support stable path handling.

Changes

Cohort / File(s) Summary
Path and Flag Normalization Utilities
crates/fbuild-build/src/zccache.rs
Adds path_arg_for_compile_cwd to convert absolute paths into canonicalized, compile-CWD-relative forms; adds normalize_flags_for_compile_cwd to rewrite compiler flags containing path arguments (e.g., -I, -isystem, -isysroot, --sysroot); modifies compile_cwd_from_output to return canonicalized workspace paths. Includes unit tests covering canonicalization and flag rewriting behavior.
Compiler Integration
crates/fbuild-build/src/compiler.rs
Updates compile_source to conditionally generate path arguments and normalize flags using zccache utilities when compiler_cache is present; reuses earlier compile_cwd computation for run_command instead of recomputing.
Test Updates
crates/fbuild-build/tests/zccache_hit_across_workspace_rename.rs
Introduces cwd_display_path helper to canonicalize and normalize workspace paths; updates assertions validating zccache log cwd= fields to compare against normalized expected paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

  • Build: enable zccache strict path validation FastLED#2378: The introduced path canonicalization and flag-rewriting utilities (path_arg_for_compile_cwd, normalize_flags_for_compile_cwd) directly enable stable/absolute compiler path enforcement, supporting zccache's strict-paths validation requirements.

Poem

🐰 Paths are canonicalized, neat and clean,
Flags rewritten to stable forms pristine,
Compile directories no longer shift,
A gift for zccache, a wonderful gift!

🚥 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 accurately describes the main change: normalizing zccache compile paths by canonicalizing the inferred CWD and rewriting path-bearing compiler flags relative to it.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/zccache-canonical-workspace-paths

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
crates/fbuild-build/src/zccache.rs (1)

287-302: Prefix-ordering note — no bug, but worth a safety check as prefixes grow.

Current prefixes (-I, -isystem, -iquote, -idirafter, -include, -imacros, -isysroot) don't collide because Rust's strip_prefix is case-sensitive and -I uses uppercase I while the rest use lowercase i. If a future prefix is added (e.g., another uppercase-I-starting flag, or a lowercase one that is itself a prefix of another, like hypothetical -i before -include), the first-match iteration could mis-split. Consider either sorting by descending length or asserting no-prefix-of-another in a unit test when the list is next modified.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/fbuild-build/src/zccache.rs` around lines 287 - 302,
split_joined_path_flag can mis-split if a shorter prefix appears before a longer
one that shares the same start; update the prefix handling in
split_joined_path_flag by ordering the prefix array by descending length (so
longer prefixes like "-isystem" are checked before "-I") or implement a unit
test that asserts no prefix is a prefix of another to prevent regressions when
modifying the list; reference the prefix array in split_joined_path_flag and add
the sorting or test near that function to guarantee safe matching as new
prefixes are added.
crates/fbuild-build/src/compiler.rs (1)

579-594: Optional: consider documenting the limited flag coverage of normalize_flags_for_compile_cwd.

normalize_flags_for_compile_cwd only rewrites include-family flags and --sysroot (see flag_takes_path_argument / split_joined_path_flag in zccache.rs). Other path-bearing compile-step flags that can appear in flags/extra_pre_flags/extra_flags — e.g. -B<prefix>, -fprofile-dir=<dir>, -fdebug-prefix-map=<old>=<new>, -specs=<path>, -Wp,-MD,<path>, or -L<dir>/-Wl,...=<path> when a link step reuses this entry point — will still be passed through verbatim and can leak absolute workspace paths into the zccache key. Not a correctness bug for the common compile path today, but worth a short doc comment at the call site (or on normalize_flags_for_compile_cwd) so future flag additions remember to extend the allow-list.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/fbuild-build/src/compiler.rs` around lines 579 - 594, Call site lacks
documentation that normalize_flags_for_compile_cwd only rewrites include-style
flags and --sysroot; update the compiler.rs block (where all_flags is built
using normalize_flags_for_compile_cwd with compile_cwd) to add a short comment
explaining the limited coverage and reference the helper functions that
determine this behavior (flag_takes_path_argument and split_joined_path_flag in
zccache.rs), so future maintainers know other path-bearing flags (e.g. -B,
-fprofile-dir, -fdebug-prefix-map, -specs, -Wp,-MD, -L, -Wl) may still contain
absolute paths and must be added to the allow-list if needed. Ensure the comment
sits immediately above the compile_cwd conditional (around
normalize_flags_for_compile_cwd usage) and mentions compile_cwd, all_flags, and
the zccache helpers by name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/fbuild-build/src/compiler.rs`:
- Around line 579-594: Call site lacks documentation that
normalize_flags_for_compile_cwd only rewrites include-style flags and --sysroot;
update the compiler.rs block (where all_flags is built using
normalize_flags_for_compile_cwd with compile_cwd) to add a short comment
explaining the limited coverage and reference the helper functions that
determine this behavior (flag_takes_path_argument and split_joined_path_flag in
zccache.rs), so future maintainers know other path-bearing flags (e.g. -B,
-fprofile-dir, -fdebug-prefix-map, -specs, -Wp,-MD, -L, -Wl) may still contain
absolute paths and must be added to the allow-list if needed. Ensure the comment
sits immediately above the compile_cwd conditional (around
normalize_flags_for_compile_cwd usage) and mentions compile_cwd, all_flags, and
the zccache helpers by name.

In `@crates/fbuild-build/src/zccache.rs`:
- Around line 287-302: split_joined_path_flag can mis-split if a shorter prefix
appears before a longer one that shares the same start; update the prefix
handling in split_joined_path_flag by ordering the prefix array by descending
length (so longer prefixes like "-isystem" are checked before "-I") or implement
a unit test that asserts no prefix is a prefix of another to prevent regressions
when modifying the list; reference the prefix array in split_joined_path_flag
and add the sorting or test near that function to guarantee safe matching as new
prefixes are added.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 71a9364b-df0e-433e-a151-39a6cba55978

📥 Commits

Reviewing files that changed from the base of the PR and between ada3b60 and 11fd09f.

📒 Files selected for processing (3)
  • crates/fbuild-build/src/compiler.rs
  • crates/fbuild-build/src/zccache.rs
  • crates/fbuild-build/tests/zccache_hit_across_workspace_rename.rs

@zackees zackees merged commit dab5a0c into main Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant