Search code examples
rustrust-cargo

What's the correct way to add workspace dev-dependencies in Cargo.toml?


In my virtual manifest Cargo.toml:

[workspace.dev-dependencies]
serial_test = "2.0.0"

In a non-virtual manifest Cargo.toml:

[dev-dependencies]
serial_test.workspace = true

Which gives the following error:

Caused by:
  error inheriting `serial_test` from workspace root manifest's `workspace.dependencies.serial_test`

Caused by:
  `dependency.serial_test` was not found in `workspace.dependencies`

This works for the dependencies section. How should workspace dependencies be specified for dev-dependencies?


Solution

  • Declare it like any other dependency in the workspace, like this:

    [workspace.dependencies]
    serial_test = "2.0.0"
    
    [dev-dependencies]
    serial_test.workspace = true
    

    Whether a dependency is a dev-dependency or not only applies to the individual package; both [dependencies] and [dev-dependencies] can use data from [workspace.dependencies].