0

in my rust project, i run cargo vendor and vendored all dependencies in vendor folder. The .cargo/config.toml file is updated to point to vendor/ folder.

[source.vendored-sources]
directory = "vendor"

Some of the vendored crates i have patched, so they are moved from vendor to patch folder, and Cargo.toml is updated as

[patch.crates-io]  
patched-crate = {path = "patch/patched-crate"}

All builds fine, and runs fine.

I use nvim + rust-analyser, with appropriate plugins. When i open a file from patched crate, rust-analyzer complains that it cannot read metadata of the patched crate. It also gives a solution that it can be fixed by adding the patched crate to the workspace in Cargo.toml

LSP[rust_analyzer] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/vimalkum/src/vector-collector/vector/patch/hyper-openssl/Cargo.toml, cargo 1.58.0 (f01b232bc 2022-01-19): Failed to run `
"cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/vimalkum/src/vector-collector/vector/patch/hyper-openssl/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: curren
t package believes it's in a workspace when it's not:
current:   /home/vimalkum/src/vector-collector/vector/patch/hyper-openssl/Cargo.toml
workspace: /home/vimalkum/src/vector-collector/vector/Cargo.toml
this may be fixable by adding `patch/hyper-openssl` to the `workspace.members` array of the manifest located at: /home/vimalkum/src/vector-collector/vector/Cargo.toml
Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.

When i add the patched crate to workspace

[workspace]
members = [
  ".",
  "lib/crate1",
  "lib/crate2",
  "patch/*",
  "vendor/*".
] 

i get build errors that it cannot load manifest of the vendored crate

cargo build --release --no-default-features --features ocp-logging
error: failed to load manifest for workspace member `/home/vimalkum/src/vector-collector/vector/vendor/azure_storage`

Edit 1

As suggested in a comment, I updated Cargo.toml with only the patch directories. And when i open in it nvim, i get error

LSP[rust_analyzer] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/vimalkum/src/vector-collector/vector/Cargo.toml, cargo 1.58.0 (f01b232bc 2022-01-19): Failed to run `"cargo" "metadata" "
--format-version" "1" "--manifest-path" "/home/vimalkum/src/vector-collector/vector/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: failed to select a version for the requirement
 `hyper-rustls = "^0.23.0"`
candidate versions found which didn't match: 0.22.1
location searched: directory source `/home/vimalkum/src/vector-collector/vector/vendor` (which is replacing registry `crates-io`)
required by package `aws-config v0.9.0 (/home/vimalkum/src/vector-collector/vector/patch/aws-config)`
perhaps a crate was updated and forgotten to be re-vendored?

but vendor folder contains hyper-rustls version version = "0.22.1"

weima
  • 4,653
  • 6
  • 34
  • 55
  • Have you tried removing `"vendor/*"` from the list, but leaving `"patch/*"`? – PitaJ Oct 12 '22 at 19:16
  • @PitaJ i tried, but still getting error. updated the question – weima Oct 12 '22 at 19:24
  • So something is requiring `hyper-rustls = "^0.23.0"` but you have version `0.22.1` vendored. Have you tried vendoring the newer version instead? – PitaJ Oct 12 '22 at 19:38

0 Answers0