Skip to content

fix(crate_universe): trust lockfiles of non-root crate universes - #29

Open
alexmohr wants to merge 1 commit into
score_mainfrom
fix/crate-universe-trust-non-root-lockfile
Open

alexmohr wants to merge 1 commit into
score_mainfrom
fix/crate-universe-trust-non-root-lockfile

Conversation

@alexmohr

Copy link
Copy Markdown

Summary

Partial backport of bazelbuild#4109 (commit 2f690546, released in 0.71.1): when a crate universe belongs to a non-root module and ships a lockfile, crate_universe/extensions.bzl uses that lockfile as-is and skips the digest check (repin = False).

The cargo-bazel-lock.json digest covers the cargo-bazel, cargo and rustc versions and the canonical manifest labels. These differ between the module that produced the lockfile and the consumer, and between a root and a non-root manifest label. A dependency that ships a lockfile generated with rules_rust >= 0.71.1 (for example eclipse-opensovd/mbedtls-rs) therefore fails on 0.68.x with Digests do not match. The consumer cannot repin it either, because the lockfile lives in the read-only module cache.

reference_integration currently carries this change as patches/rules_rust/002-crate-universe-trust-non-root-lockfile.patch so it can use dependencies that ship lockfiles, such as mbedtls-rs. It can drop that patch once a release with this change is tagged (for example 0.68.3-score).

Checklist

  • I have tested my changes locally
  • I have added or updated documentation
  • I have linked related issues or discussions
  • I have added or updated tests

Related

Notes for Reviewers

Scope of the backport:

  • Backported: non-root universe with a lockfile -> the lockfile is trusted, no digest check.
  • Not backported: upstream also calls fail() for a non-root universe without a lockfile. That is left out on purpose, so such universes keep repinning as before and no existing consumer breaks.
  • Root modules are unchanged: they still run determine_repin.
  • Upstream bundled this change into the link_deps annotation PR. Only the lockfile handling is taken here.

Verification:

  • pre-commit run --files crate_universe/extensions.bzl: buildifier format and lint, and typos, pass.
  • Probe workspace with Bazel 8.8.2, the S-CORE and BCR registries and local_path_override of rules_rust to this branch, running bazel build --nobuild @mbedtls-rs//...:
rules_rust mbedtls-rs Result
score_main (2098bd5) f9c5e92, ships cargo-bazel-lock.json fails: Digests do not match in determine_repin
this branch f9c5e92, ships cargo-bazel-lock.json passes
this branch without lockfile passes (repins as before)

No test is added: the behaviour depends on module_ctx and on is_root of a second module, which needs a multi-module bzlmod integration setup that the fork does not have. Upstream did not add a test for it either.


Alexander Mohr alexander.m.mohr@mercedes-benz.com, Mercedes-Benz Tech Innovation GmbH
Provider Information

When a crate universe belongs to a non-root module and ships a
lockfile, use the lockfile as-is and skip the digest check
(repin = False).

The digest covers the cargo-bazel, cargo and rustc versions and the
canonical manifest labels, which differ between the module that
produced the lockfile and the consumer. Dependencies that ship a
lockfile generated for rules_rust >= 0.71.1 consumers (for example
eclipse-opensovd/mbedtls-rs) therefore fail on 0.68.x with
"Digests do not match", and the lockfile lives in the read-only
module cache, so it cannot be repinned from the consumer.

This is a partial backport of upstream bazelbuild#4109
(commit 2f69054, released in
0.71.1). Upstream also fails hard for non-root universes without a
lockfile. That part is left out on purpose: such universes keep
repinning, so existing consumers are not broken.

Upstream: bazelbuild#4109
Signed-off-by: Alexander Mohr <alexander.m.mohr@mercedes-benz.com>
@alexmohr
alexmohr marked this pull request as ready for review November 28, 2026 21:58
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