bazelbuild / bazelbuild/rules_rust
crates_vendor: [patch.crates-io] fails to patch primary/transitive dependencies for `path = "..."`
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
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](https://github.com/bazelbuild/rules_rust/blob/main/crate_universe/src/metadata/metadata_annotation.rs#L234), referencing the [package's `Package.source` being None, which is expected for a local project](https://docs.rs/cargo_metadata/latest/cargo_metadata/struct.Package.html#structfield.source).
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
```
Contributor guide
Assessment
This issue has not been assessed yet.