crate_universe: resolve annotation patches against the current module (#4425) ### Problem `crate.annotation(patches = ...)` labels are stored in `cargo-bazel-lock.json` as canonical strings, so their form depends on which module was root when the lockfile was pinned (`@@//…` vs `@@my_module+//…`). Since #3521 the digest ignores the repo part, so the lockfile is reused unchanged when the module is consumed by another root. `_generate_hub_and_spokes` then passes the stored string straight to `http_archive`/`git_repository`, and `@@//` resolves to the *consumer's* main repo: ``` Error in patch: Cannot find patch file: /path/to/consumer/bazel/patches/foo.patch ``` Re-pinning from the consumer only moves the breakage: the module then fails as root. No single lockfile works in both setups. ### Fix Build an index from the current invocation's annotation tags, `(crate, repo-stripped label) → label as resolved now`, and use it to rewrite lockfile patch labels before creating crate repos. The repo-stripping is the same normalization the digest already uses. Labels with no matching annotation keep their lockfile value. There's no lockfile format change, no digest change and no forced re-pin. ### Testing A module owns a `crate.from_cargo` hub with a patched crate annotation and its own lockfile pinned as root. A second root module depends on it through `local_path_override` and `include()`s its `*.MODULE.bazel`. - Before: the crate fetch fails because the patch path resolves inside the consumer. - After: the patch resolves inside the owning module from both roots. Happy to add a regression test under `test/` (a nested module with a lockfile and a patch annotation, built as root and as a dependency) if that's the preferred shape. ### Notes Other label-valued annotation fields (`deps`, `build_script_data`, `additive_build_file`, …) may have the same problem when rendered into spoke BUILD files. This PR only fixes `patches`, which `extensions.bzl` consumes directly. Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: UebelAndre <github@uebelandre.com>
This repository provides rules for building Rust projects with Bazel.
The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/rust.
General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.
Please refer to the full documentation.