Skip to content

cargo new with workspace: exclude/include #13198

@dumindu

Description

@dumindu

Problem

Currently when we run cargo new command inside a workspace, it gives following warnings,

warning: compiling this new package may not work due to invalid workspace configuration

current package believes it's in a workspace when it's not:
current:   /path/to/workspace/new_crate/Cargo.toml
workspace: /path/to/workspace/new_crate/Cargo.toml

this may be fixable by adding `new_crate ` to the `workspace.members` array of the manifest located at: /path/to/workspace/Cargo.toml
Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.

Additionally, while running cargo run new_crate it gives following errors(but no issue with cargo run --bin new_crate)

warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
   Compiling api v0.1.0 (/path/to/workspace/new_crate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/api api`

Proposed Solution

  1. We can add following commands
  • cargo new -we and cargo new -wi
  • cargo new --workspace exclude and cargo new --workspace include
  1. The scope of the resolver is bit unclear for me. If we add cargo workspace command, we can add more subcommands I think.

Notes

No response

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