fix: canonicalize manifest labels in lockfile digests#3901
Open
brianduff wants to merge 1 commit intobazelbuild:mainfrom
Open
fix: canonicalize manifest labels in lockfile digests#3901brianduff wants to merge 1 commit intobazelbuild:mainfrom
brianduff wants to merge 1 commit intobazelbuild:mainfrom
Conversation
Ignore repository names when hashing splicing metadata so cargo-bazel lockfiles remain portable between root and dependency contexts. Reject canonicalization collisions explicitly and cover both behaviors with unit tests.
f2932f0 to
1b3fded
Compare
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 & Solution Overview
cargo-bazel-lock.jsondigests currently includeSplicingMetadata.manifests, which is keyed by full Bazel labels.That makes the digest sensitive to whether the same
Cargo.tomlis evaluated in the root module context or as a dependency module under bzlmod.Concretely, the same manifest can appear as:
//impl/rust:Cargo.toml@@published_ruleset+//impl/rust:Cargo.tomlThose labels serialize differently even when the manifest contents and resulting Cargo graph are identical, so a checked-in
cargo-bazel-lock.jsoncan validate in the producer repo and then fail downstream withDigests do not matchwhen that repo is consumed as a dependency.This change canonicalizes manifest labels only for lockfile hashing:
To avoid introducing a new hard failure mode, the digest path now serializes canonicalized manifest entries in a collision-tolerant way:
That keeps root-vs-dependency lockfiles portable without panicking or erroring when canonicalization removes repository-name distinctions.
This PR also repins the checked-in example lockfiles whose checksums change under the new digest algorithm.
Testing Done
bazel test //crate_universe:unit_test --test_output=errors//:Cargo.tomland@@published_ruleset+//:Cargo.tomlproduce the same digestexamples/crate_universebazel run //vendor_external:crates_vendor --show_progress_rate_limit=5 --curses=yes --color=yes --terminal_columns=143 --show_timestamps --verbose_failures --jobs=30 --announce_rc --experimental_repository_cache_hardlinks --disk_cache= --sandbox_tmpfs_path=/tmpinexamples/crate_universeand confirmed it reachesAnalyzed target //vendor_external:crates_vendor/Build completed successfullyinstead of failing on a stale digestI also validated the behavior with a minimal producer/consumer repro outside this repo:
Producer
MODULE.bazel:Consumer
MODULE.bazel:Repro steps:
CARGO_BAZEL_REPIN=1 bazel build //:repro_libbazel build @lockfile_repro//:repro_libBefore this patch, step 2 failed because the digest changed under
@@lockfile_repro+//.With this patch, both builds succeed.
Notes for Reviewers
The main tradeoff here is that repository identity is intentionally removed from the digest input for manifest labels.
That is deliberate because repository identity changes between root and dependency contexts, while the Cargo inputs stay the same.
If maintainers think repository identity should remain semantically relevant here, then the long-term fix likely needs a different repo-neutral manifest identity instead of raw Bazel labels.