Skip to content

cargo run should discover executables in workspace packages #3713

@sunjay

Description

@sunjay

I recently left this comment on #3529 but unfortunately that issue was fixed and closed before my suggestion could be taken into account. I asked @alexcrichton and he said it would work for me to just create a new issue here.

Here's my original suggestion from that issue:

Would love to see this! Even better would be if I could use the same run syntax as before but cargo would build and run the appropriate executable in my packages.

To explain further, let's say I had this structure:

src/
  bin/
    a.rs
    b.rs
    bb.rs

I used to be able to run:

cargo run --bin a
cargo run --bin b
cargo run --bin bb

With workspaces, I split that into two crates like this:

a/
  src/
    bin/
      a.rs
b/
  src/
    bin/
      b.rs
      bb.rs

It would be really nice if I could still run the same commands as above. The executable names are still the same and unique. They just belong to different crates in the same workspace now.

If the executables across crates aren't unique, then you should definitely make -p required, but otherwise it's way more ergonomic (and easier to remember) to just use the old commands.

It's the difference between cargo run -p b --bin b and cargo run --bin b.

Basically, it would be great if cargo run could run binaries from any package within a workspace. That way you could be sitting at the workspace root and run executables that you would normally have to change directories to run.

@alexcrichton also mentioned that this might be neat for tests as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-workspacesArea: workspacesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-run

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions