Fix crates_repository cache invalidation on Bazel 8#3967
Merged
UebelAndre merged 1 commit intobazelbuild:mainfrom Apr 15, 2026
Merged
Fix crates_repository cache invalidation on Bazel 8#3967UebelAndre merged 1 commit intobazelbuild:mainfrom
UebelAndre merged 1 commit intobazelbuild:mainfrom
Conversation
In Bazel 8, --incompatible_no_implicit_watch_label defaults to true, so repository_ctx.path(label) no longer implicitly watches the resolved file. Add explicit repository_ctx.watch() calls for cargo_lockfile, lockfile, and manifests so Bazel re-fetches the repository when these inputs change.
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.
Problem
In Bazel 8,
--incompatible_no_implicit_watch_labeldefaults totrue(bazelbuild/bazel#23861). This meansrepository_ctx.path(label)no longer implicitly watches the resolved file for changes.crates_repositoryresolves itscargo_lockfile,lockfile, andmanifestsinputs viarepository_ctx.path(label)but never explicitly callsrepository_ctx.watch()on them. As a result, when these files change on disk, Bazel doesn't know it needs to re-fetch the repository — the generateddefs.bzlbecomes stale, causing errors like:This is especially painful in setups where
crates_repositoryinputs come from another external repository (e.glocal_repository) with a long-running Bazel server. CI is unaffected because it always starts with clean state. The only workaround today isbazel cleanorbazel sync --only=<repo>.Fix
Add explicit
repository_ctx.watch()calls forcargo_lockfile,lockfile(optional, guarded byif lockfiles.bazel), and each entry inmanifests, immediately afterget_lockfiles()returns in_crates_repository_impl.Testing
Verified in a large monorepo (Bazel 8.6.0, rules_rust 0.66.0) with a nested workspace where
crates_repositoryinputs come from alocal_repository. Before the fix, changingCargo.tomlor lock files requiredbazel cleanto pick up changes. After the fix, Bazel automatically re-fetches the crate repositories.Related