crate_vendor is broken in recent releases
bazel run //third_party/rust:update-repos
INFO: Invocation ID: 515c31d7-a136-47ee-9680-d0dd6f8f2018
ERROR: no such package '@@cargo_bazel_bootstrap//': The repository '@@cargo_bazel_bootstrap' could not be resolved: Repository '@@cargo_bazel_bootstrap' is not defined
ERROR: third_party/rust/BUILD.bazel:3:14: every rule of type crates_vendor implicitly depends upon the target '@@cargo_bazel_bootstrap//:binary', but this target could not be found because of: no such package '@@cargo_bazel_bootstrap//': The repository '@@cargo_bazel_bootstrap' could not be resolved: Repository '@@cargo_bazel_bootstrap' is not defined
Documentation for implicit attribute cargo_bazel of rules of type crates_vendor:
The cargo-bazel binary to use for vendoring. If this attribute is not set, then a `CARGO_BAZEL_GENERATOR_PATH` action env will be used.
ERROR: Analysis of target '//third_party/rust:update-repos' failed; build aborted: Analysis failed
setting bootstrap = True in crate_universe_dependencies fails for not being able to find cargo:
bazel run //third_party/rust:update-repos
INFO: Invocation ID: cea31b86-7111-4f5a-8caf-16cccb4a3c48
INFO: Repository cargo_bazel_bootstrap instantiated at:
WORKSPACE:325:28: in <toplevel>
/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/external/rules_rust/crate_universe/repositories.bzl:24:30: in crate_universe_dependencies
/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/external/rules_rust/crate_universe/deps_bootstrap.bzl:17:31: in cargo_bazel_bootstrap
Repository rule cargo_bootstrap_repository defined at:
/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/external/rules_rust/cargo/private/cargo_bootstrap.bzl:225:45: in <toplevel>
ERROR: An error occurred during the fetch of repository 'cargo_bazel_bootstrap':
Traceback (most recent call last):
File "/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/external/rules_rust/cargo/private/cargo_bootstrap.bzl", line 208, column 40, in _cargo_bootstrap_repository_impl
cargo_bin = repository_ctx.path(tools.cargo),
Error in path: Unable to load package for @@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools//:bin/cargo: The repository '@@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools' could not be resolved: Repository '@@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools' is not defined
ERROR: no such package '@@cargo_bazel_bootstrap//': Unable to load package for @@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools//:bin/cargo: The repository '@@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools' could not be resolved: Repository '@@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools' is not defined
ERROR: /Users/xiaoyishi/Projects/monorepo/third_party/rust/BUILD.bazel:3:14: //third_party/rust:update-repos depends on @@cargo_bazel_bootstrap//:binary in repository @@cargo_bazel_bootstrap which failed to fetch. no such package '@@cargo_bazel_bootstrap//': Unable to load package for @@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools//:bin/cargo: The repository '@@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools' could not be resolved: Repository '@@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools' is not defined
as we are using nightly toolchains:
rust_register_toolchains(
edition = "2021",
versions = [
"nightly/2024-04-05",
],
)
I haven't dug into the issue, but this is a change between 0.49.3 and 0.52.2.
Would you please share your relevant MODULE config and your //third_party/BUILD.bazel file?
The thing is, there are 4 different ways to vendor in rules_rust:
from_crate (using cargo.toml)
- local (vendors to third_party/crates)
- remote (vendors somewhere in the cache)
from_spec (using direct deps in BUILD.bazel)
- local
- remote
In a nutshell, remote vendoring requires an extra script to run correctly, see this example:
https://github.com/bazelbuild/rules_rust/tree/main/examples/bzlmod/all_deps_vendor
Also, remote vendoring can be leaky meaning vendored deps may update during regular builds.
Local vendoring, that means the deps are correctly stored in the thirdparty/crate folder, doesn't need a script and is not leaky meaning vendored deps only update when you call the vendor target.
See this example for local from_spec vendoring. https://github.com/marvin-hansen/bazel_rust_cross_llvm
The other thing is, if you use vendoring with from_crate (and a Cargo.toml), then it takes a bit more research because the bazelmod examples have not been added yet.
I know the documentation isn't super clear in this area, but afaik, if you configure proper local vendoring stuff just builds.