Repository navigation
fix(daemon): restore depfile on cache hit (closes #643) - #644
Merged
Merged
Conversation
Pins the bug: when zccache wraps `clang++ -MD -MF <depfile>` (the shape emitted by build systems with `deps = gcc`), a cache hit currently restores only the `.obj` — the user's `.d` is silently absent. The downstream build tool then records zero dependencies for the object and stops recompiling when included headers change, producing stale objects and `undefined symbol` link errors after `git pull`. Wires `current_depfile_dest: Option<NormalizedPath>` into `CachedHitMaterializeRequest` so the caller can supply *this build's* `-MF` destination on a hit (independent of where the depfile lived when the miss recorded it). The handler body intentionally does not yet consume the field — the next commit implements the restore and flips this test from RED to GREEN. Refs #643.
When zccache wraps `clang++ -MD -MF <depfile>` (the shape build systems
emit for `deps = gcc`), the miss path now captures the user's depfile
bytes as a second artifact output, and the hit path writes them back
alongside the `.obj` to the *current* build's `-MF` destination.
Before this fix, only the `.obj` was restored on a hit. The build tool
then read an absent depfile, recorded zero dependencies for the object,
and stopped recompiling when included headers changed — silently
producing stale objects and `undefined symbol` link errors after
`git pull`.
The depfile destination on hit is derived from the current request's
dep_flags (not the cached basename), so renamed-output / cross-worktree
hits restore the depfile to the correct place. Legacy single-output
artifacts cached before this fix keep working unchanged: the hit-path
materializer only consults `current_depfile_dest` when the artifact
actually has a second payload. Cache-file mtime preservation is
unchanged — the depfile write goes through the same
`write_payloads_par_with_mtime_floor` path the `.obj` already used.
Touched layers:
- `depgraph::depfile::user_depfile_destination` — single source of truth
for "where does the current build want its depfile?"
- `pipeline::handle_compile_request` — on miss, after parse_depfile_path
succeeds in `UserSpecified` / `UserDefault`, also reads the depfile
bytes and threads them into `MissArtifactStoreRequest::user_depfile`.
- `miss_store::store_single_output` — extends the artifact with a second
output when `user_depfile` is `Some`.
- `cached_hit::materialize_cached_compile_hit` — extra
`current_depfile_dest` field; routes payloads[1] to it when both the
artifact has two outputs and the field is `Some`.
- `hit_branches::{try_fast_hit, try_depgraph_cached_hit}` — derive
`current_depfile_dest` from passed-in `dep_flags`, also stamp it into
the new `RequestCacheEntry::depfile_path` so the ultra-fast request
cache path restores the depfile on subsequent hits.
- `request_cache::RequestCacheEntry` + `keys::request_cache_entry` —
store the depfile destination as a `CachedRequestPath` so
cross-worktree fast-path hits rebase it to the new root.
Coordinated with FastLED/FastLED — downstream stale-build investigation.
Closes #643.
The depfile-fix work accidentally overwrote the in-progress Static Library (.a) Caching planning content with its own scratch notes. This commit restores tasks/todo.md to main's content so the PR is scoped only to the depfile-on-cache-hit fix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Jun 4, 2026
zackees
added a commit
that referenced
this pull request
Jun 4, 2026
Patch release for #643/#644 — restore depfile on cache hit. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Jun 4, 2026
zackees
added a commit
to FastLED/FastLED
that referenced
this pull request
Jun 4, 2026
) 1.11.11 ships forge-ci/zccache#644 — cache hits now restore the user's `-MF <path>` depfile alongside the .obj. Without it, build systems reading depfiles silently record zero dependencies for cached objects, and from then on header changes never trigger rebuilds. The symptom for FastLED was `undefined symbol: ...` link errors hours after a `git pull` that modified a transitively included header, with no obvious reason for the build to be using stale objects. A clean rebuild worked around it but threw away the whole incremental-build benefit. Closes the local-side of forge-ci/zccache#643. The fix landed in forge-ci/zccache@5fb9f54 and shipped to PyPI as zccache 1.11.11. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On a cache hit zccache currently restores only the
.obj— the user's.ddepfile (-MD -MF <path>) is silently absent. Downstream build systems withdeps = gccthen read an absent depfile, record zero dependencies for the object, and stop recompiling when included headers change. After agit pullthat touches headers, this surfaces as stale incrementals andundefined symbollink errors.This PR makes the miss path capture the user's depfile bytes as a second artifact output, and the hit path write them back to the current build's
-MFdestination alongside the.obj. Cache-file mtime preservation is unchanged.Downstream impact
Reported in the FastLED organization by way of #643's reproducer (12-line shell script). Without this fix the symptom is a quietly stale
.owhose missing header changes only surface at link time — the kind of bug that wastes hours bisecting "a working build went bad."Root cause
cached_hit::materialize_cached_compile_hitbuilt itstargetsvector purely frompayloads.len()×output_names. It never wrote the depfile that the original miss-time depfile parse had seen, because:output_data(the.obj) intoArtifactData::outputs[0], and.dhere, please put one back."Fix
depgraph::depfile::user_depfile_destination(dep_flags, output)— single source of truth for "where does the current build want its depfile?" (-MF <path>when present, else<output>.dwhen-MDis set, elseNone). Applies only to theUserSpecified/UserDefaultstrategies; theInjectedstrategy (zccache added the flags purely for its own depgraph use) is intentionally excluded.pipeline.rs: on the C/C++ miss path, afterparse_depfile_pathsucceeds forUserSpecified/UserDefault, alsostd::fs::read(path)and thread the bytes into the newMissArtifactStoreRequest::user_depfilefield.miss_store::store_single_output: whenuser_depfileisSome, push a secondArtifactOutputfor the depfile (basename used as a stable identifier; the on-disk destination on hit always comes from the current request).cached_hit::materialize_cached_compile_hit: newcurrent_depfile_dest: Option<NormalizedPath>field. When the cached artifact has 2 outputs AND the field isSome, routespayloads[1]to that destination. Legacy single-output cache entries from before this PR are untouched (the 2-output check is what gates the behavior, not the field alone).hit_branches::{try_fast_hit, try_depgraph_cached_hit}: derivecurrent_depfile_destfrom the passed-indep_flags, and stash it into theRequestCacheEntry::depfile_pathso subsequent ultra-fasttry_request_cache_hitcalls (which run before arg parsing) also restore the depfile.RequestCacheEntry/request_cache_entry: depfile destination is stored as aCachedRequestPathso cross-worktree shareable hits rebase it to the current key root just likesource_path/output_path. If the user supplied an absolute path outside the key root, the entry falls back to worktree-bound semantics.Coordinated with
FastLED/FastLED— downstream stale-build investigation.Test plan
7bf6ae6) —cached_hit_restores_user_depfile_alongside_object. Run against unmodifiedmain: the assertionassert!(depfile_dest.as_path().exists(), ...)panics with the issue-depfile not restored on cache hit -> incremental build silently produces stale objects #643 stale-incremental-build message. Run against the impl commit (b1d6c37): passes.cached_hit_object_only_artifact_ignores_depfile_dest— passing acurrent_depfile_destwith a 1-output cached artifact must NOT manufacture a depfile.depgraph::depfilecover the threeuser_depfile_destinationbranches (mf_path wins /-MDderives default / no flags → None).soldr cargo fmt --allclean.soldr cargo clippy --workspace --all-targets -- -D warningsclean../test(-p zccache --lib) all 1690 unit tests green../test --integration— not run locally (low disk; pre-existing flake noted indaemon_rustc_restore_testis on the rustc path and unaffected by this fix, which only touches C/C++ depfile flow).Out of scope (mentioned, not fixed)
store_rustc_outputs) and is not modified here. Its dep-info file is already part of the snapshotted rustc outputs./showIncludeshas no on-disk depfile to capture; theShowIncludesstrategy is correctly excluded by the helper.🤖 Generated with Claude Code