crates_vendor: [patch.crates-io] fails to patch primary/transitive dependencies for `path = "..."`
Using [patch.crates-io] in your Cargo.toml to patch to local copies of a crate via CRATE_NAME = { path = "path/to/crate"} is currently failing with an error of style: Error: The package 'Name("zerocopy") Version { major: 0, minor: 6, patch: 1 }' has no source info so no annotation can be made. This fails for patching both primary and transitive dependencies.
The error is coming from this line, referencing the package's Package.source being None, which is expected for a local project.
This same workflow functions for its CRATE_NAME = { git = "git_repository"} equivalent.
Minimal repro:
Command:
bazel run //:crates_vendor
Directory structure:
WORKSPACE
BUILD
Cargo.toml
empty/zerocopy
Cargo.toml
src/lib.rs
src/lib.rs
WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_rust",
sha256 = "696b01deea96a5e549f1b5ae18589e1bbd5a1d71a36a243b5cf76a9433487cf2",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.11.0/rules_rust-v0.11.0.tar.gz"],
)
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
rules_rust_dependencies()
rust_register_toolchains()
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
crate_universe_dependencies()
BUILD
load("@rules_rust//crate_universe:defs.bzl", "crates_vendor")
crates_vendor(
name = "crates_vendor",
manifests = ["//:Cargo.toml"],
mode = "local",
vendor_path = "vendor",
)
Cargo.toml
[package]
name = "my-third-party"
version = "0.1.0"
[dependencies]
zerocopy = "0.6.1"
[patch.crates-io]
zerocopy = { path = 'empty/zerocopy' }
[workspace]
src/lib.rs
// This file is left intentionally blank
empty/zerocopy/Cargo.toml
[package]
name = "zerocopy"
version = "0.6.1"
empty/zerocopy/src/lib.rs
// This file is left intentionally blank
I think I'm running into this when trying to change a crate dependency from being from a repository to being from a path. We have a bunch of crates in a cargo-based repository, and I'm trying to iterate on some work where I need to change the cargo crate source and then see if the fix works for the bazel-based rust code. How can I do this? I don't want to/cannot bring the cargo-based crate code all the way into bazel and create BUILD files for it all and everything, but I would like to be able to temporarily point cargo-bazel at a path to it while I am working on it, then when everything is prepped, revert back to the published crate.
This seems like a pretty common use case, how do people do it?