Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with multiple nested workspace roots?

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.

like image 965
Olivier Avatar asked Apr 16 '18 04:04

Olivier


1 Answers

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 (contain package.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] in Cargo.toml).
  • All workspace crates defined in workspace.members point back to the workspace root with package.workspace.
like image 161
ljedrz Avatar answered Sep 22 '22 11:09

ljedrz