Problem
If we cargo vendor our dependencies, and one of the crates in the vendor folder is inheriting package info from its Workspace, cargo build --offline would fail with errors like:
Caused by:
error inheriting `version` from workspace root manifest's `workspace.package.version`
Caused by:
failed to find a workspace root
Steps
- Add a crate that is from a project using Workspace inheritance
$ tail Cargo.toml
...
[dependencies]
lib-in-workspace = { git = "ssh://git@internal-git-service/rust-project-using-workspace.git", tag = "v0.176.0" }
...
- Vendor dependencies:
$ cargo vendor >> .cargo/config.toml
$ tail .cargo/config.toml
...
[source."ssh://git@internal-git-service/rust-project-using-workspace.git"]
git = "ssh://git@internal-git-service/rust-project-using-workspace.git"
tag = "v0.176.0"
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
$ cat Cargo.lock
...
[[package]]
name = "lib-in-workspace"
version = "0.176.0"
source = "git+ssh://git@internal-git-service/rust-project-using-workspace.git?tag=v0.176.0#7efcf95d618e9af79431e036414903fe3b4954b8"
dependencies = [
"aho-corasick",
"bstr",
"cc",
...
]
...
- Build app offline
$ cargo build --offline --release
error: failed to get `aho-corasick` as a dependency of package `app v0.1.0 (/home/hunts/code/app)`
Caused by:
failed to load source for dependency `aho-corasick`
Caused by:
Unable to update registry `crates-io`
Caused by:
failed to update replaced source registry `crates-io`
Caused by:
failed to parse manifest at `/home/hunts/code/app/vendor/lib-in-workspace/Cargo.toml`
Caused by:
error inheriting `version` from workspace root manifest's `workspace.package.version`
Caused by:
failed to find a workspace root
- Check what's in the crate's Cargo.toml
$ head vendor/lib-in-workspace/Cargo.toml
[package]
name = "lib-in-workspace"
version.workspace = true
authors.workspace = true
description.workspace = true
edition.workspace = true
publish.workspace = true
Possible Solution(s)
I'm no familiar with the workspace design, but it feels like we need to replace the workspace variables with real values when vendor a crate, or will need to provide metadata of the workspace the crate is sourced from.
Notes
I've anonymized the package/lib names related to our internal systems, hope that won't cause inconvenience in understanding the problem.
Version
cargo 1.64.0 (387270bc7 2022-09-16)
release: 1.64.0
commit-hash: 387270bc7f446d17869c7f208207c73231d6a252
commit-date: 2022-09-16
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
os: Ubuntu 22.04 (jammy) [64-bit]
Problem
If we
cargo vendorour dependencies, and one of the crates in the vendor folder is inheriting package info from its Workspace,cargo build --offlinewould fail with errors like:Steps
Possible Solution(s)
I'm no familiar with the workspace design, but it feels like we need to replace the workspace variables with real values when vendor a crate, or will need to provide metadata of the workspace the crate is sourced from.
Notes
I've anonymized the package/lib names related to our internal systems, hope that won't cause inconvenience in understanding the problem.
Version