Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Where to put the .cargo/config.toml file in a cargo workspace?

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/mylib and /projects/foo/bar/baz/mybin, and there are Cargo configs at /projects/foo/bar/baz/mylib/.cargo/config.toml and /projects/foo/bar/baz/mybin/.cargo/config.toml, Cargo does not read those configuration files if it is invoked from the workspace root (/projects/foo/bar/baz/).

Also, it’s not exactly specified either in 14.3. Cargo Workspaces or 3.6. Configuration where to put a .cargo/config.toml that would be common to all the packages in the workspace.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Like if path/to/workspace/root is the the workspace root folder, my dependencies should look for vendored external dependencies in path/to/workspace/root/vendoredcode.

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 .cargo/config.toml file?

PS:
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 main.rs and/or 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.

>Solution :

Just put the .cargo/config.toml at the root of the workspace.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading