How can you have multiple nested workspace with Cargo?
I have the following project structure:
myworkspace
├── project_a
│ └── Cargo.toml
├── project_b
│ └── Cargo.toml
│ └── project_b_dependency
| └── Cargo.toml
└── Cargo.toml
Where project_b_dependency
is a big library which is a git submodule which has a workspace by itself.
I get an error when I run cargo build
because there is a workspace within a workspace.
$ cargo build
error: multiple workspace roots found in the same workspace:
/myworkspace
/myworkspace/project_b/project_b_dependency
Is there a simple work-around? I want to keep project_b_dependency
in source control as a submodule.
This is not a duplicate of Refactoring to workspace structure causes extern crate imports to not work because I want to know how I can deal with nested workspaces.
Workspaces can't be nested; as the docs state:
A crate may either specify package.workspace or specify
[workspace]
. That is, a crate cannot both be a root crate in a workspace (contain[workspace]
) and also be a member crate of another workspace (containpackage.workspace
).
The Cargo workspace RFC also specified this:
A workspace is valid if these two properties hold:
- A workspace has only one root crate (that with
[workspace]
inCargo.toml
).- All workspace crates defined in
workspace.members
point back to the workspace root withpackage.workspace
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With