Skip to content

Accept the BUILD.bazel that cargo-bazel writes into a vendored crate - #2190

Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
bazel-gap/cargo-vendor-check
Open

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
bazel-gap/cargo-vendor-check

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

In a Bazel workspace with a rules_rust crate hub, a vendored crate no longer breaks bazel cquery //... and bazel query 'deps(//...)', and vendor --check, vex, repair and a repeated scan --mode vendored no longer take the crate for a changed one after a build has written its BUILD.bazel into the copy.

Three commits on main (e6c5f50); nothing this builds on is still open. The first commit is tests only and passes on main's product code. The second is the change. The third narrows it after a code review; this description is of the three together.

Decisions for the maintainer

  • A new file write. socket-patch now writes two lines into .bazelignore for .socket/vendor/cargo, in workspaces whose module files declare a crate.from_cargo hub of the project's crates. They follow the rules of the Go lines, opt-out included.
  • One file is outside the check, where Bazel does not read it. Under such a hub, and under a .bazelignore line that covers the copy, a BUILD.bazel under cargo-bazel's banner is not compared, whoever wrote it. There it does not reach the crate and is no package of the workspace. Without the line it is a changed copy, as on main.
  • crates_vendor in local mode was read, not run. What this description says of it is from the rules_rust 0.75.0 source. This change does nothing for it.

The full list, with the alternatives, is at the end.

What the code does today

Vendored mode keeps a patched crate under .socket/vendor/cargo/<uuid>/<crate>/ and points a [patch.crates-io] path entry at it. Under a rules_rust crate hub (crate.from_cargo) the next build is the patched one. From rules_rust 0.59.0 on, the hub's tool, cargo-bazel, also writes a BUILD.bazel into that copy each time Bazel evaluates the hub: it renders the build file of every crate a Cargo workspace takes from a path to <path>/BUILD.bazel (crate_universe/src/rendering.rs, render_build_files).

Right after a patched and green build with rules_rust 0.75.0:

  • socket-patch vendor --check exits 1 (vendor_inventory_mismatch): the scan recorded no such file;
  • socket-patch vex leaves the patch out and, with nothing else to attest, exits 1 and writes no document;
  • the next scan --mode vendored downloads the crate again and removes the file, and the next evaluation of the hub writes it back;
  • for a vendored crate that has a dependency, bazel cquery //... and bazel query 'deps(//...)' fail. Bazel reads the file as a package of the workspace, and that package names a repository only the hub sees (No repository visible as '@crates__<dependency>' from main repository). bazel build //... and bazel query //... pass.

The first commit holds all four on real Bazel as known gaps. With rules_rust 0.56.0, which the fixture uses on Bazel 7.7.2, a build writes no file and none of the four happens.

What changes

Both parts apply only where the Bazel workspace has a hub of the project's crates: MODULE.bazel at the Bazel root, or a file it includes, calls from_cargo on the extension crate of @rules_rust//crate_universe:extensions.bzl (or of extension.bzl, its older name), the call is a statement of its own, and it names the project's Cargo.lock as cargo_lockfile or the project's root Cargo.toml among manifests, by a label of the main repository written out as a string. A call in a comprehension or behind a condition, one that names its files through a constant, and the hub of another Cargo workspace of the checkout are not such a hub. In every other project, inside a Bazel workspace or not, nothing changes.

The two parts are given here in the order of the first two commits. They depend on each other: the file of part 1 is accepted only under a line of part 2.

1. The build file is no change of the copy. The inventory check of a Cargo copy in its place leaves that one file out of the comparison when all of this holds:

  • it is a regular file named BUILD.bazel in the copy's own directory, and the inventory does not list it. A build file the crate ships is listed and stays held to the crate's bytes;
  • it starts with the banner of every file cargo-bazel renders: a line of #, the line # @generated, and a line that starts with # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. The template is byte for byte the same at rules_rust 0.56.0, 0.59.0, 0.65.0 and 0.75.0;
  • the project is in a Bazel workspace with a hub of its crates, as above;
  • a line of the root's .bazelignore covers the copy: the line of part 2, or one of the user's own for the directory or one above it.

Every recorded file is still compared and any other file the scan did not record still fails. One function is behind vendor --check, vex, repair and the re-run of a vendored scan (verify_vendored_patch_record), so all four follow. The check that holds a download staged for a copy is the code main has, untouched.

2. Bazel is kept out of the copies. socket-patch already keeps .bazelignore lines for the Go module copies under .socket. It now keeps one for .socket/vendor/cargo as well, under a comment line of its own:

# socket-patch: patched crate copies, not Bazel packages (to opt out, comment out the next line)
.socket/vendor/cargo

scan --mode vendored writes the two lines and vendor --revert takes them away. Every rule of the Go lines holds: the file is the one at the Bazel root and the path is from that root; nothing is added where a line already covers the directory; a path line the user commented out is never touched again; a file that cannot be written is the warning bazelignore_not_updated; a run whose --ecosystems leaves cargo out adds no line. No command gained a call: every command that can write or remove a vendored copy already ends in the one helper.

With the line the copy is no package: //... holds the user's own targets, both commands pass, and the build is the same patched one, because the hub reads the copy by its path, copies the directory into a repository of its own and renders the build file there again (crate_universe/private/local_crate_mirror.bzl).

Output. A person is told when the lines change, in the existing line of that helper: Updated <path>: the lines that keep patched crate copies under .socket out of Bazel's packages, or Removed <path>: no patched crate copy is left under .socket. The Go lines read as before. The detail of bazelignore_not_updated now says the patched copies and names bazel cquery //... among the commands that can otherwise fail; that wording changes for Go too. No JSON field, event or code is new.

How narrow the acceptance is, and what it leaves unchecked

Only the banner is read. The rest of the file differs from one machine and one ruleset release to the next (the command that renders it again, the platforms, the labels of the dependencies), and a hub can add text of the user's own to it, so nothing recorded could be compared with it.

So a build file that someone else puts into the copy under the same banner is not told apart from cargo-bazel's. That is why the acceptance needs the .bazelignore line. The vendored flow holds what such a file can do, on real Bazel:

  • It does not reach the crate: the build still prints the patched marker.
  • Under the line it is no package of the workspace, and vendor --check passes.
  • With the line commented out it is a package, bazel build //... builds its target, and vendor --check exits 1 with vendor_inventory_mismatch.

The price: without the line, cargo-bazel's own file is a changed copy again, as on main. That is the case for a user who commented the line out, for a file socket-patch could not write (bazelignore_not_updated), and for a checkout vendored by an earlier release until a command that writes the line has run there (scan --mode vendored, repair, apply).

In a workspace without a hub of the project's crates such a file is a changed copy, as on main.

Why only under a hub in the module files

rules_rust's crates_vendor in local mode names a path crate by its package in the checkout (rendering.rs, make_deps). That was read in the 0.75.0 source and not run. There the file in the copy is what Bazel builds the crate from, so accepting it would leave a build-affecting file unchecked, and a .bazelignore line would take the crate out of the build. A hub of the older WORKSPACE system (crates_repository) is not looked for either. For both, this change does nothing.

Contents

Part Lines
crates/socket-patch-core/src/bazel/cargo_bazel.rs (new): the banner, the hub lookup, the predicate, with their unit tests +295
crates/socket-patch-core/src/bazel/ignore.rs: the pair for the crates, each ecosystem's scope, whose lines changed, whether a line covers a copy; unit tests +206 / -59
crates/socket-patch-core/src/vendor/verify.rs: the exemption where a copy is verified in its place; unit test +203 / -6
crates/socket-patch-cli/src/commands/mod.rs: the commands' one .bazelignore helper +30 / -21
crates/socket-patch-core/src/bazel/mod.rs, vendor/cargo_config.rs +1, +1 / -1
crates/socket-patch-cli/tests/e2e_bazel_build/cargo.rs: the two flows and three tests without Bazel +555 / -165 (first commit +380 / -76)
crates/socket-patch-cli/tests/fixtures/bazel/rules_rust/bzlmod/common/Cargo.lock: the dependency +9 (first commit)
docs/ecosystems.md, crates/socket-patch-cli/CLI_CONTRACT.md +110 / -2, +24 / -1
scripts/loc-budget.json: the cap of the bazel group follows the code 2486 to 2591

The bazel group grows by 105 lines of code by scripts/loc-budget.py (66 in the second commit, 39 in the third); verify.rs adds 17 and the CLI helper about 10 outside it. In all: 11 files, +1435 / -256. No workflow changes.

The fixture's crate gets a dependency, a second crate that the tests' stand-in registry serves. Without one, the build file cargo-bazel writes names no repository of the hub and the two failing commands could not be a committed test. The hosted flow builds the same crate and its expectations are unchanged.

What it proves, and where

All runs on macOS arm64. The third commit changed the product and the tests, so each paragraph says at which head its runs were made: "the second commit" is c09af56, "the head" is the third.

Real Bazel, as the reusable workflow's run step runs the Cargo leg (the tests whose names start with cargo::, two at a time, a fresh output root per run):

Bazel rules_rust vendored flow hosted flow
9.3.2 0.75.0 pass at the head (both flows together, 143 s) pass at the head
8.8.2 0.75.0 pass at the second commit, 191 s pass at the second commit, 159 s
7.7.2 0.56.0 pass at the second commit, 112 s pass at the second commit, 84 s

Bazel 8.8.2 and 7.7.2 have not run the third commit; CI runs them.

The vendored flow has no known gap left. The scan's files include .bazelignore with the pair. After the build, vendor --check passes and vex attests the crate with either ruleset; //... is the consumer alone and bazel cquery //... and bazel query 'deps(//...)' pass. With the path line commented out, on 9.3.2 and 8.8.2 //... holds two targets in the copy, both commands fail on the repository of the dependency and (at the head, on 9.3.2) vendor --check exits 1; on 7.7.2, where no file is written, all three pass. vendor --revert takes the pair away with the copy. On a second machine a second scan downloads nothing and changes no file. A changed library is still vendor_hash_mismatch.

The first commit on main's product code: its tests without Bazel pass, and its two flows pass on Bazel 9.3.2 with the known gaps as they are, the two failing commands among them. The Bazel run was made on the two earlier states of main this branch was based on during the work; after the last rebase onto e6c5f50 only its tests without Bazel were run again.

With the product change taken out, the vendored flow fails on Bazel 9.3.2 at its first assertion about the scan's files, and two of the three Cargo tests without Bazel fail.

Without Bazel:

  • cargo::only_the_build_file_of_cargo_bazel_is_no_change_of_a_vendored_copy: eight vendored checkouts with one unrecorded build file each. Only cargo-bazel's file in a workspace with a hub of the project's crates, under the line of the scan, is no change. In a checkout that is no Bazel workspace, in a workspace whose module file makes no hub or the hub of another Cargo workspace, with the path line commented out, without the banner, named BUILD, or in src/, the copy is the changed one it was.
  • cargo::the_vendored_crates_get_a_bazelignore_line_where_a_crate_hub_builds_them: the pair is written under a hub of the project's crates, and not without one or under the hub of another Cargo workspace; a run that leaves Cargo out adds none; a commented-out path line stays as it is over a scan and a repair, with no warning; vendor --revert removes the pair from a file that keeps the user's line; a person is told in the crate wording.
  • The 18 existing tests of the Go lines in the same target pass unchanged, file contents and human lines included.

Unit tests: the hub lookup (the tag, both file names, another name for the ruleset, an included file; either Cargo file, under each spelling of the main repository; the files of another Cargo workspace or repository, files named through a constant, a call behind and or in a comprehension; a project below the root), the predicate (each banner line, from the start of the file; with and without a .bazelignore line that covers the crate), the check (one difference per row; a second file, a build file in a sub-directory or a changed recorded file beside the accepted one; no line, a commented-out line, a line for another directory, a line for a directory above; a link of that name; a build file the crate ships; a crate that ships module files of its own in a project without Bazel), and the pair of the crates in sync. Seventeen mutations of the second commit's product code, one condition each, were each caught there: sixteen by the unit tests, one by the test without Bazel. At the head, three more of the new rules (the line, the statement of its own, the named files) are each caught by the unit tests.

Nothing changes without a hub: a binary built from main's product code and one from this branch were run in the same vendored Cargo checkout, in four checkouts (no workspace file; MODULE.bazel without a hub; a hub's module file beside the project; MODULE.bazel with the hub), fourteen shapes of the copy and eight commands (vendor --check, vex, scan --mode vendored, repair, vendor, list, apply, vendor --revert), each with --json and without. Of 448 comparisons the 336 in the three checkouts without a hub are the same in exit codes, both streams, the VEX document and every file left. The 18 that differ are in the checkout with the hub: the build file under the banner for the first four commands, and vendor --revert in each shape, which removes the .bazelignore pair. This comparison was made at the second commit and not repeated at the head: the third commit only narrows where the two parts apply, and its tests without Bazel hold the checkouts without a hub to main's behaviour.

Suites at the head: clippy for the workspace and for the real-Bazel test target; cargo check of every target; the unit tests of bazel:: (128) and vendor::verify (26); the CLI targets vendor, repair, vex, cli and spawn_env_hygiene; e2e_bazel_build without Bazel (51); the script tests. At the second commit: the core unit suite (8342 tests) and its 32 integration targets; the CLI unit suite; twenty CLI targets that reach the changed code (vendor, repair, scan, vex, apply, rollback, remove, get, scan_vendor_e2e, in_process_vendor, in_process_rollback_vendored, in_process_remove_repair_lifecycle, vendor_revert_tamper_e2e, mode_migration_cargo, e2e_vex_lockfile, e2e_vex_vendor, e2e_vendor_cargo_build, e2e_vendor_gem_build, e2e_vendor_golang_build, e2e_golang_build), cli, spawn_env_hygiene, e2e_bazel_build without Bazel, and the script tests. No existing expectation changed. Two tests of e2e_vendor_cargo_build did not run to their assertions here: they start x86_64 toolchains from 2020, which this machine cannot execute. CI runs them.

Code review

/code-review high on the first two commits gave nine findings. Each was confirmed by reading the code. Seven are fixed in the third commit, two are not.

Fixed:

  1. The acceptance did not need the .bazelignore line. A planted BUILD.bazel under the banner passed vendor --check and vex while Bazel read it as a package, wherever the line was missing: a checkout vendored by an earlier release, a file that could not be written, the opt-out. The file is now let through only in a copy that a line covers.
  2. Any from_cargo call counted as a hub. One in a comprehension or behind a condition, and the hub of another Cargo workspace of the checkout, got the line and the acceptance. A hub is now a call that is a statement of its own and names the project's Cargo.lock or root Cargo.toml by a written-out label.
  3. A message was dropped. A human run that changed the Go lines for one project and the crate lines for another under the same root printed only the first. Each kind of copy is now named.
  4. The module files were read on every command of a project with vendored crates, before the check that finds nothing to change. They are now read only when a pair for the crates is about to be added.
  5. The table of directories compared a string to find the row of the crates, and sync handed back a joined phrase. The row now says it is the crates', and sync hands back the kinds of copy.
  6. Two definitions of .socket/vendor/cargo. One now.
  7. The bound of the Bazel root applied to the read-only verdict of vendor --check and vex without the docs saying so. The docs now name the cases (see "Not covered").

Not fixed:

  • A hub and a crates_vendor target in local mode over the same Cargo workspace. The line would take the crate out of that vendor target's build. This is known from the ruleset's source, not from a build, and finding such a target means reading every BUILD file of the workspace. It stays the documented case in which the user comments the line out; with the third commit, cargo-bazel's file is then a changed copy there, which is right where that file is what the crate is built from.
  • A crate that ships a BUILD.bazel of its own. By the ruleset's source cargo-bazel writes its file over the crate's, and the copy then reads as changed after a build, as on main. Accepting a recorded file that was replaced needs a build on real Bazel with such a crate first.

Not covered

  • crates_vendor (local or remote mode) and a WORKSPACE-era crates_repository hub: neither was run on real Bazel. What is said of them is from the rules_rust 0.75.0 source, and this change does nothing for them.
  • A workspace that has both a crate.from_cargo hub and a local-mode crates_vendor target over the same Cargo workspace. The line is written there and, by the source, would take the crate out of that vendor target's build. Such a workspace must comment the line out; the docs say so. Nothing detects it.
  • A hub that names its Cargo files through a constant, or names only member manifests and no lock, is not taken for a hub of the project: no line is written and cargo-bazel's file is a changed copy, as on main.
  • The Bazel root is found only where socket-patch looks for one: above the project's own directory only inside a git checkout whose .git belongs to the user, to root or to the user sudo ran for. In a submodule, or in a checkout a CI container mounts from another user, both parts are off, and vendor --check fails after a build there although it passes on a developer's machine. The docs say so.
  • How often the module files are read: once for each vendored crate that holds an unrecorded build file under the banner, on each command that verifies it. Not cached.
  • A crate that ships a BUILD.bazel of its own. By its source (write_outputs), which no build here has run for such a crate, cargo-bazel writes its file over that one. The inventory lists the crate's file, so the copy reads as changed after a build, as before, until a second scan or repair restores it.
  • A project below the Bazel root on real Bazel. Unit tests hold that the line then carries the project's path.
  • Bazel leaves an ignored directory out of every glob() of a package above it. A target that hands the project's files to a cargo of its own through such a glob no longer receives the copies. From rules_rust 0.59.0 on, cargo-bazel's own file in the copy has the same effect. Not measured for Cargo.
  • rules_rust releases between 0.59.0 and 0.74.x: the banner was compared, no build ran.
  • Linux and Windows. Every run here is on macOS arm64.

The decisions in full

  1. Writing the Cargo line. socket-patch writes into .bazelignore for vendored crates wherever the module files declare a crate.from_cargo hub. The alternative is to document the line and leave the two commands failing after every build.
  2. The banner as the test. One file in the vendored copy is outside vendor --check: a BUILD.bazel under cargo-bazel's banner, in a workspace with a hub of the project's crates, in a copy that a .bazelignore line covers. It does not change what the crate is built from, and under the line it is no package. The other choices are to leave the check failing after every build, or to record the file's hash at the first check after a build, which is a second piece of state for a file that differs per machine.
  3. crates_vendor and WORKSPACE hubs. They stay as on main: no line, and the check fails after the ruleset writes its file. Extending either part to them needs a build on real Bazel with each first.
  4. A crate that ships its own BUILD.bazel. Accepting a recorded build file that cargo-bazel replaced is a few lines. It needs a build on real Bazel with such a crate first.
  5. The warning's wording. The detail of bazelignore_not_updated is now the same sentence for Go and Cargo copies.

🤖 Generated with Claude Code

Vendored mode keeps a patched crate under `.socket/vendor/cargo` and
points a `[patch.crates-io]` path entry at it. Under a rules_rust crate
hub (`crate.from_cargo`) the next build is the patched one, and from
rules_rust 0.59.0 on the hub's tool, cargo-bazel, also writes a
`BUILD.bazel` into that copy: it renders the build file of a crate the
workspace takes from a path to `<path>/BUILD.bazel`, each time Bazel
evaluates the hub (`crate_universe/src/rendering.rs`,
`render_build_files`). The real-Bazel flow of vendored mode already
pinned, as known gaps, that `vendor --check` and `vex` then take the copy
for a changed one. This adds what was not yet measured about that file
and records what the code does with it today. No product code changes.

The crate of the fixture gets a dependency: a second crate, which the
stand-in registry serves and the fixture's `Cargo.lock` lists, with a
placeholder for its checksum as for the crate itself. Without a
dependency the build file that cargo-bazel renders names no repository
of the hub, and Bazel analyses it without trouble. The hosted flow
builds the same crate and passes as before; the index of its patch
registry names the dependency as crates.io's.

On real Bazel (`cargo::vendored_from_cargo_with_config`; run on 9.3.2
with rules_rust 0.75.0):

- The file starts with the banner of every file cargo-bazel renders.
- It makes the copy a package of the user's workspace:
  `bazel query //...` lists two targets there, and `bazel build //...`
  passes. The package names the repository of the dependency, which
  only the hub sees, so `bazel cquery //...` and
  `bazel query 'deps(//...)'` fail on it (`No repository visible as
  '@crates__...'`): a third known gap of the flow. With a `.bazelignore`
  line for `.socket/vendor/cargo`, which the test writes as a user
  would, `//...` is the user's own target again, both commands pass, and
  the build is still the patched one: the hub reads the copy by its
  path, copies it into a repository of its own and renders the build
  file of that repository again.
- So a build file that someone else puts into the copy does not reach
  the crate: with one under the same banner the build still prints the
  patched marker. It is a package of the workspace all the same, and
  `bazel build //...` builds its target. `vendor --check` reports it
  (`vendor_inventory_mismatch`), as it reports the file cargo-bazel
  wrote.

Without a Bazel (`cargo::a_build_file_in_a_vendored_copy_is_a_changed_copy`),
six checkouts with one build file each that the scan did not record:
`BUILD.bazel` in the copy's own directory under the banner in a Bazel
workspace with a crate hub, the same in a checkout that is no Bazel
workspace and in a workspace whose module file makes no hub, one
without the banner, one named `BUILD`, and one in `src/`. Every one is
a changed copy today: `vendor --check` exits 1, `vex` leaves the patch
out and writes no document, and a second `scan --mode vendored`
downloads the crate again and removes the file. The scan writes no
`.bazelignore` in any of them.

`vex` of the flows writes its document beside the checkout through
`Cell::document`, which needs no Bazel, so the hermetic test shares it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
In a Bazel workspace with a rules_rust crate hub, the build after
`scan --mode vendored` is the patched one, and from rules_rust 0.59.0 on
the hub's tool, cargo-bazel, writes a `BUILD.bazel` into the vendored
copy under `.socket/vendor/cargo/<uuid>/<crate>/` each time Bazel
evaluates the hub. Two things went wrong with that file, right after a
patched and green build:

- The scan recorded no such file, so every check of the copy against
  the ledger's inventory took it for a changed one
  (`vendor_inventory_mismatch`): `vendor --check` exited 1, `vex` left
  the patch out and wrote no document, and the next vendored scan
  downloaded the crate again.
- Bazel read the file as a package of the user's workspace. For a crate
  with a dependency that package names a repository only the hub sees,
  and `bazel cquery //...` and `bazel query 'deps(//...)'` failed on it.

Both are fixed where the workspace has such a hub, and nowhere else:
`MODULE.bazel` at the Bazel root, or a file it includes, calls
`from_cargo` on the extension `crate` of rules_rust's
`//crate_universe:extensions.bzl` (or `extension.bzl`, its older name).
`bazel::cargo_bazel::hub` reads that with the reader the VEX step uses.

The file is no change of the copy

The inventory check of a Cargo copy in its place leaves that one file
out. It is the file when all of this holds:

- a regular file named `BUILD.bazel` in the copy's own directory that
  the inventory does not list. A build file the crate ships is listed
  and stays held to the crate's bytes;
- it starts with the banner of every file cargo-bazel renders (a line
  of `#`, `# @generated`, and a line that starts with `# DO NOT MODIFY:
  This file is auto-generated by a crate_universe tool.`; the template
  is the same from rules_rust 0.56.0 to 0.75.0);
- the project is in a Bazel workspace with a crate hub. In any other
  project the file is a changed copy, as before.

Every recorded file is still compared and any other unrecorded file
still fails. `verify_vendored_patch_record` is the one check behind
`vendor --check`, `vex`, `repair` and the re-run of a vendored scan, so
all four follow: the check passes, `vex` attests the crate, `repair`
restores nothing, and a second scan reports the copy `already_vendored`
without a download. The exemption is made there, on the files found in
the copy, and `verify_dir_inventory`, which also holds a download staged
for a copy, compares as before.

Only the banner is read. The rest of the file differs from one machine
and ruleset release to the next (the command that renders it again, the
platforms, the labels of the dependencies), and a hub can add text of
the user's own to it, so nothing recorded could be compared with it. So
a build file of someone else's under the same banner passes
`vendor --check`. It does not reach the crate, because the hub copies
the directory into a repository of its own and renders the build file
there again (`local_crate_mirror.bzl`): the build still prints the
patched marker.

Bazel is kept out of the copies

`bazel::ignore::sync`, which keeps a `.bazelignore` line for the Go
module copies under `.socket`, keeps one for `.socket/vendor/cargo` too,
under a comment line of its own (`# socket-patch: patched crate copies,
not Bazel packages (to opt out, comment out the next line)`). Every
command that can write or remove a vendored copy already ends there, so
`scan --mode vendored` writes the pair and `vendor --revert` takes it
away, and the rules of the Go lines hold: nothing is added for a
directory a line already covers, a commented-out path line is the
user's "no", a file that cannot be written is the warning
`bazelignore_not_updated`, and a run whose `--ecosystems` leaves `cargo`
out adds none. The call now takes the two ecosystems apart and says
whose lines changed, so a person reads `patched crate copies` or
`patched Go module copies` in the line that reports the file. The
detail of the warning speaks of patched copies and names
`bazel cquery //...` beside the two commands it named.

With the line the copy is no package: `//...` is the user's own
targets, `bazel cquery //...` and `bazel query 'deps(//...)'` pass, and
a build file that someone else puts into a copy is no package either.
The build is the same patched one, because the hub reads the copy by
its path.

Why only under a hub in the module files: rules_rust's `crates_vendor`
in local mode names a path crate by its package in the checkout
(`rendering.rs`, `make_deps`; read, not run). There the file in the copy
is what the crate is built from, and a line would take the crate out of
the build. A hub of the older `WORKSPACE` system is not looked for
either. In such a workspace nothing changes: no line, and the file is a
changed copy.

Not covered: a crate that ships a `BUILD.bazel`. cargo-bazel writes over
it (`write_outputs`; read, not run), and the copy reads as changed after
a build, as before.

Tests

The vendored flow on real Bazel loses its three known gaps. The scan
writes the `.bazelignore` pair among its files. Right after the build
`vendor --check` passes and `vex` attests the crate with either ruleset,
`//...` is the consumer alone, and the two commands that analyse every
target pass. With the path line commented out, as a user who declines
it has it, the package is back where the ruleset writes the file, and
both commands fail on the repository of the dependency. `vendor
--revert` takes the pair away with the copy. On a second machine the
second scan downloads nothing and changes no file; the file under
someone else's banner passes the check and is no package under the
line, and with the line commented out `bazel build //...` builds its
target; the changed library is still `vendor_hash_mismatch`.

Without a Bazel, of the six build files of the earlier commit only the
first is no change of the copy; the five others, the workspace without
a hub among them, are the changed copies they were, and `repair` after
the scan restores nothing in any of them. A second test holds the line:
written under a hub and not without one, not added by a run that leaves
Cargo out, declined by a commented-out path line, removed with the
copies, and reported to a person in its own words. Unit tests hold the
hub lookup, the predicate and the check, one difference per row, and
the pair of the crates in `sync`.

The cap of the `bazel` group in `scripts/loc-budget.json` follows the
code (2486 to 2552).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A review of the change found that it accepted more, and wrote more, than
it had shown to be safe.

The acceptance. `vendor --check`, `vex`, `repair` and a repeated vendored
scan left an unrecorded `BUILD.bazel` under cargo-bazel's banner out of
the comparison wherever the workspace had a crate hub. Only the banner is
read, so a file that someone else puts into a vendored copy under that
banner passed too, and without a `.bazelignore` line over the copy (a
checkout vendored by an earlier release, a file that could not be
written, the user's opt-out) Bazel reads that file as a package and
`bazel build //...` builds its targets. The file is now let through only
in a copy that a line of the root's `.bazelignore` covers, where it is no
package. Without the line it is the changed copy it was before this
change.

The hub. Any `crate.from_cargo` call counted, so the `.bazelignore` pair
was written, and the file accepted, for a call in a comprehension or
behind a condition, and for the hub of another Cargo workspace of the
checkout, which writes nothing into this project's copies. A hub of the
project's crates is now a call that is a statement of its own and names
the project's `Cargo.lock` as `cargo_lockfile`, or its root `Cargo.toml`
among `manifests`, by a label of the main repository written out as a
string. Anything else leaves the copies and the file as they are.

Smaller things from the same review:

- a human run that changed the Go lines for one project and the crate
  lines for another under the same Bazel root printed only the first
  message; each kind of copy is now named;
- the module files are read only when a pair for the crates is about to
  be added, not on every command of a project with vendored crates;
- the row of the crates in the table of directories says that it is
  theirs, where the loop compared a string, and `sync` hands back the
  kinds of copy whose lines changed, not a joined phrase;
- one definition of `.socket/vendor/cargo` (`CARGO_VENDOR_DIR`).

The docs say where the Bazel root is not found (a submodule, a checkout
of another user): both parts are off there.

Not changed, and still as the description says: a workspace with both a
hub and a `crates_vendor` target in local mode over the same Cargo
workspace, and a crate that ships a `BUILD.bazel` of its own. Each needs
a build on real Bazel first.

The Cargo flows pass on Bazel 9.3.2 with rules_rust 0.75.0; the vendored
flow now also holds that with the path line commented out `vendor
--check` exits 1, for the file cargo-bazel wrote and for a planted one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 20, 2026 19:21
@cursor

cursor Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes vendored integrity checks and writes project .bazelignore in Bazel workspaces, which can affect vendor --check, vex, and scan behavior though only under narrowly defined rules_rust hub conditions.

Overview
rules_rust crate hubs no longer treat cargo-bazel’s generated BUILD.bazel as vendored drift, and vendored scan / revert flows keep Bazel from loading .socket/vendor/cargo as workspace packages.

A new cargo_bazel module detects a rules_rust crate.from_cargo hub that names this project’s Cargo.lock or Cargo.toml, recognizes cargo-bazel’s banner on BUILD.bazel, and treats that file as non-inventory only when a root .bazelignore line covers the copy. vendor verification strips that file before inventory comparison, so vendor --check, vex, repair, and repeat scan --mode vendored stay green after a hub build.

.bazelignore sync now maintains a crate pair (alongside Go) when Cargo is in scope and a hub exists; CLI output names which copy kinds changed. Docs and CLI_CONTRACT describe the exemption and expanded bazelignore_not_updated scope.

E2E and unit tests cover vendored Bazel flows, hub edge cases, and banner/ignore rules; fixture Cargo.lock gains a dependency so hub build files exercise repo visibility failures.

Reviewed by Cursor Bugbot for commit 1e3fd30. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant