Skip to content

Support intra-workspace dependencies via all_crate_deps - #4239

Open
abezukor wants to merge 1 commit into
bazelbuild:mainfrom
abezukor:abe/all_crate_deps_intra_workspace_dependencies
Open

Support intra-workspace dependencies via all_crate_deps#4239
abezukor wants to merge 1 commit into
bazelbuild:mainfrom
abezukor:abe/all_crate_deps_intra_workspace_dependencies

Conversation

@abezukor

Copy link
Copy Markdown
Contributor

Supersedes #3308. Fixes #1923

crates_universe drops dependency edges between crates of the same Cargo workspace, leaving users to restate them by hand in BUILD files while Cargo.toml already describes them.

Track those edges instead of discarding them, and render them into their own _FIRST_PARTY_* maps that all_crate_deps(first_party = True) opts into. The choice is per target at load time rather than per repository at generation time, so enabling it needs no repin and no configuration.

The Bazel repository holding the workspace's crates is derived from the rule's existing cargo_lockfile label, so there is no new user-facing attribute. That label stays out of the lockfile digest for the same reason label_injection_mapping does: canonical repository names are consumer-specific, and hashing one would demand a producer-side repin that a read-only bzlmod cache cannot perform.

Third-party output is unaffected. Rendering the test fixtures before and after this change produces a diff of pure additions: the new first_party parameter, its docstring, and six empty map literals for workspaces without intra-workspace dependencies.

Almost all written with AI, starting with #3308 as a base. I have manually reviewed the code.

@google-cla

google-cla Bot commented Aug 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@abezukor
abezukor force-pushed the abe/all_crate_deps_intra_workspace_dependencies branch from f2e08e4 to a932fab Compare August 25, 2026 00:25
`crates_universe` drops dependency edges between crates of the same Cargo
workspace, leaving users to restate them by hand in BUILD files while
Cargo.toml already describes them.

Track those edges instead of discarding them, and render them into their
own `_FIRST_PARTY_*` maps that `all_crate_deps(first_party = True)` opts
into. The choice is per target at load time rather than per repository at
generation time, so it needs no configuration. A lockfile written before
this change carries no such edges, so it must be repinned once before the
flag returns anything.

The Bazel repository holding the workspace's crates is derived from the
rule's existing `cargo_lockfile` label, so there is no new user-facing
attribute. That label stays out of the lockfile digest for the same
reason `label_injection_mapping` does: canonical repository names are
consumer-specific, and hashing one would demand a producer-side repin
that a read-only bzlmod cache cannot perform.

Coverage goes in the existing `cargo_workspace` integration test rather
than a new one: its `printer` crate now reaches its sibling `rng` through
the flag, and `printer:unit_test` calls into that sibling at runtime,
while `num_printer` keeps declaring `//printer` by hand so both styles
stay exercised. Its lockfile is repinned accordingly; most of that diff
is the pending `extra_deps` build script migration rather than this
change.

Third-party output is unaffected. Rendering the test fixtures before and
after this change produces a diff of pure additions: the new
`first_party` parameter, its docstring, and six empty map literals for
workspaces without intra-workspace dependencies.
@abezukor
abezukor force-pushed the abe/all_crate_deps_intra_workspace_dependencies branch from a932fab to 6c4cb45 Compare August 25, 2026 00:32
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.

Crates Universe: Do I need to replicate intra-workspace Cargo.toml dependencies in BUILD.bazel files?

1 participant