Skip to content

cargo add should support adding an inherited dependency to a workspace #13810

@heaths

Description

@heaths

Problem

We are using a workspace to centrally managed certificate configuration including dependencies. This makes it easier to ship some - perhaps all - workspace packages on separate schedules with approved dependency versions (likely the latest minor or patch version). Unfortunately, cargo add - which we expect most crate developers will use - cannot add a dependency to a workspace.

If our workspace is Cargo.toml and member crates are under sdk/ e.g., sdk/core/Cargo.toml, what should happen somehow is:

  1. The dependency and any enabled features are added to the workspace Cargo.toml under [workspace.dependencies].
  2. An inherited dependency i.e., name = { workspace = inherit } is added to whatever dependency section is chosen e.g., [workspace] by default or [dev-dependencies] when --dev is specified.

Proposed Solution

Ideally, cargo add just works without additional command line switches. This makes it easier in a monorepo with many different contributing teams that don't have to think about different paradigms than they are used to. Perhaps some configuration in .cargo/config.toml e.g.,

[dependencies]
inherit = true

If lieu of or even in addition to, it seems that cargo add {dependency} --package {package} --manifest-path {workspace cargo.toml} should do this. Currently it does not, and seems to ignore the --manifest-path. If I don't use --package and use just --manifest-path, I get an error:

error: `cargo add` could not determine which package to modify. Use the `--package` option to specify a package. 
available packages: {package list}

Notes

May be related to #12208.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions