Skip to content

Add link_deps crate_universe annotation - #4109

Merged
UebelAndre merged 3 commits into
bazelbuild:mainfrom
UebelAndre:crate_universe_cleanup
Jun 26, 2026
Merged

Add link_deps crate_universe annotation#4109
UebelAndre merged 3 commits into
bazelbuild:mainfrom
UebelAndre:crate_universe_cleanup

Conversation

@UebelAndre

@UebelAndre UebelAndre commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

#4024 now adds noisy prints that users have no way to handle when using crate_universe. This change adds annotations so the prints can be actioned.

@UebelAndre
UebelAndre requested a review from krasimirgg June 26, 2026 00:47
@UebelAndre
UebelAndre force-pushed the crate_universe_cleanup branch from 369519b to abacba6 Compare June 26, 2026 00:48
@UebelAndre
UebelAndre marked this pull request as ready for review June 26, 2026 00:50
@UebelAndre
UebelAndre force-pushed the crate_universe_cleanup branch from abacba6 to a9c26e1 Compare June 26, 2026 01:06
@UebelAndre
UebelAndre force-pushed the crate_universe_cleanup branch from a9c26e1 to 7331f02 Compare June 26, 2026 01:22
@UebelAndre
UebelAndre requested a review from illicitonion June 26, 2026 01:23
@UebelAndre
UebelAndre enabled auto-merge June 26, 2026 01:23
@UebelAndre
UebelAndre force-pushed the crate_universe_cleanup branch 4 times, most recently from a327c2c to f4b1d1f Compare June 26, 2026 04:11
if start > 0 && bytes[start - 1] == b'@' {
continue;
}
let after = start + apparent.len();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are the indices in input (a str) guaranteed to match the indices in bytes? (i.e. is input only made of non-multibyte characters?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, based on this:

https://doc.rust-lang.org/std/primitive.str.html#method.len

This length is in bytes, not chars or graphemes. In other words, it might not be what a human considers the length of the string.

@UebelAndre
UebelAndre force-pushed the crate_universe_cleanup branch from f4b1d1f to f0c543a Compare June 26, 2026 14:39
@UebelAndre
UebelAndre disabled auto-merge June 26, 2026 14:49
@UebelAndre
UebelAndre added this pull request to the merge queue Jun 26, 2026
Merged via the queue into bazelbuild:main with commit 2f69054 Jun 26, 2026
3 checks passed
rdesgroppes added a commit to rdesgroppes/protobuf that referenced this pull request Jun 27, 2026
…umers

Fixes protocolbuffers#28224.

`rules_rust` 0.71.1 (bazelbuild/rules_rust#4109) rejects any non-root
`crate_universe` extension call that does not set `lockfile`.
Therefore any Bazel build that depends on `protobuf` and use
`rules_rust` 0.71.1 fails to resolve:
```
crate_universe extension call `crates` is in a non-root module but has no lockfile. Transitive crate_universe repositories must ship a `lockfile = ...` because repinning is not supported across module boundaries.
```

Pin the resolution by committing both lockfiles and passing them to
`from_specs`:
- the `cargo-bazel-lock.json` render lockfile is what `rules_rust`
  0.71.1 requires,
- the Cargo lockfile `Cargo.lock` is needed too to generate the former.

`dev_dependency = True` is not viable because `@crate_index` feeds the
**public** `protobuf` Rust crate.

Here's a command to regenerate both lock files after changing the crate
specs:
```
bazel mod --repo_env=REPIN=1 deps
```
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Jun 30, 2026
### What does this PR do?

Bumps rules_rust_prost to 0.71.2 (same release as rules_rust, they
must stay in sync) and adds a protobuf patch that fixes a build break
introduced by rules_rust 0.71.1.

### Motivation

Renovate bumped rules_rust but left rules_rust_prost at 0.71.0.
rules_rust 0.71.1 (bazelbuild/rules_rust#4109) added a strict check:
non-root crate_universe extension calls must set a lockfile; protobuf
35.1 has no such lockfile, causing bazel mod deps to fail.
The fix (protocolbuffers/protobuf#28230) is pending upstream; the
patch is a workaround in the meantime.

### Describe how you validated your changes

bazel mod deps passes.

### Additional Notes

The patch marks protobuf's crate_universe extension as
dev_dependency = True. Bazel then skips it when protobuf is a
transitive dependency, sidestepping the lockfile requirement.
Safe here: Rust proto targets use rules_rust_prost, not protobuf's
native Rust aspect (which depends on @crate_index).
rdesgroppes added a commit to rdesgroppes/protobuf that referenced this pull request Jul 1, 2026
Fixes protocolbuffers#28224.

`rules_rust` 0.71.1 (bazelbuild/rules_rust#4109) rejects any non-root
`crate_universe` extension call that does not set `lockfile`.
Therefore any Bazel build that depends on `protobuf` and uses
`rules_rust` 0.71.1 fails to resolve:
```
crate_universe call `crates` is non-root but has no lockfile.
 Transitive crate_universe repos must ship a `lockfile` because
 repinning is not supported across module boundaries.
```

Adding lockfiles to the existing unified setup would impose `googletest`
and its transitive deps (`aho-corasick`, `regex`, ...) to downstream
consumers.
The `crate_universe` extension is therefore split into:
1. `crate` now has the required lockfiles with only crates needed for
   local and transitive builds: `linkme`, `paste`, `quote` and
   `syn`[^1],
2. `crate_dev` with `dev_dependency = True` (no lockfile needed) for
   crates only used in local tests: `googletest`[^2] and its transitive
   deps.

[^1]: `syn`'s `full` feature was previously satisfied incidentally via
`googletest`'s transitive dep.
It is now declared explicitly since `protobuf_macros` needs `Stmt` and
`Expr*` at compile-time.

[^2]: `repositories = ["crates_dev"]` prevents `googletest` from
becoming a common spec that bleeds into the production `Cargo.lock`.
rdesgroppes added a commit to rdesgroppes/protobuf that referenced this pull request Jul 1, 2026
Fixes protocolbuffers#28224.

`rules_rust` 0.71.1 (bazelbuild/rules_rust#4109) rejects any non-root
`crate_universe` extension call that does not set `lockfile`.
Therefore any Bazel build that depends on `protobuf` and uses
`rules_rust` 0.71.1 fails to resolve:
```
crate_universe call `crates` is non-root but has no lockfile.
 Transitive crate_universe repos must ship a `lockfile` because
 repinning is not supported across module boundaries.
```

Adding lockfiles to the existing unified setup would impose `googletest`
and its transitive deps (`aho-corasick`, `regex`, ...) to downstream
consumers.
The `crate_universe` extension is therefore split into:
1. `crate` now has the required lockfiles with only crates needed for
   local and transitive builds: `linkme`, `paste`, `quote` and
   `syn`[^1],
2. `crate_dev` with `dev_dependency = True` (no lockfile needed) for
   crates only used in local tests: `googletest`[^2] and its transitive
   deps.

[^1]: `syn`'s `full` feature was previously satisfied incidentally via
`googletest`'s transitive dep.
It is now declared explicitly since `protobuf_macros` needs `Stmt` and
`Expr*` at compile-time.

[^2]: `repositories = ["crates_dev"]` prevents `googletest` from
becoming a common spec that bleeds into `Cargo.lock`.
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.

2 participants