It’s stated in the Cargo Book (on page 3.6. Configuration) that when
cargo is invoked from the workspace root, the
.cargo/config.toml files specified for individual packages within the workspace do not get read.
At present, when being invoked from a workspace, Cargo does not read config files from crates within the workspace. i.e. if a workspace has two crates in it, named
/projects/foo/bar/baz/mybin, and there are Cargo configs at
/projects/foo/bar/baz/mybin/.cargo/config.toml, Cargo does not read those configuration files if it is invoked from the workspace root (
My objective here is to specify a single folder where all packages in the workspace should look for the vendored code of external dependencies, should said dependency be used in their code.
path/to/workspace/root is the the workspace root folder, my dependencies should look for vendored external dependencies in
For a single package, I’d put it
.cargo/config.toml in the package root and put the following in it:
[source.crates-io] replace-with="vendored-sources" [source.vendored-sources] directory="path/to/package/root/vendoredcode"
How to do the same for all packages in a workspace with a single
There might be some confusion due to my consistent use of the term "package" where some people might commonly use the term "crate".
I read that a single package (a folder with
Cargo.toml and an
src subfolder which contains
lib.rs) can actually contain multiple binary crates and a single library crate at the same time, so I preferred to use the term "package" instead of "crate" for it.
This choice was to avoid confusion though I recognise that while it might avoid confusion with one set of people, it might create confusion with another set of people. Hence this clarification.
Just put the
.cargo/config.toml at the root of the workspace.