New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is not possible to specify a default binary #2200

Closed
JanLikar opened this Issue Dec 6, 2015 · 12 comments

Comments

Projects
None yet
@JanLikar
Contributor

JanLikar commented Dec 6, 2015

I think it would be really great if one would be able to specify a default binary in Cargo.toml, so cargo run could be used without --bin argument when there are more binaries in a crate.

@steveklabnik

This comment has been minimized.

Member

steveklabnik commented Dec 7, 2015

👍 , with the default default being set to src/main.rs

@JanLikar

This comment has been minimized.

Contributor

JanLikar commented Dec 18, 2015

Do you think something like default-bin in [package] would be ok?

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Dec 18, 2015

I'd be a little hesitant to move on this just yet. For example there are other questions I'd have such as:

  • Should there also be a default test binary? Default bench binary?
  • Does this interact with commands like cargo rustc and cargo rustdoc where the default takes precedence over other targets?
  • Does this interact with cargo install where the default is the only one installed unless otherwise specified?

I'd want to flesh this out a bit more and see how it fits into the whole Cargo picture before landing it. FOr now --bin foo doesn't seem too costly at least for something that's largely only used during development.

@JanLikar

This comment has been minimized.

Contributor

JanLikar commented Dec 18, 2015

I agree, I will think this through.

@jadencarver

This comment has been minimized.

jadencarver commented Mar 5, 2016

+1

@andreastt

This comment has been minimized.

Contributor

andreastt commented Nov 26, 2016

I think having a run or default-run option, akin to build, under [package] would be a good idea for the reason that one might implement a program with “subcommands” as multiple binaries with the default program as the sub-program dispatcher.

Using git(1) as an example:

  • /usr/bin/git
  • /usr/lib/git-core/git-commit
  • /usr/lib/git-core/git-diff

When using git commit in the shell this passes "commit" as a string to /usr/bin/git, which ends up calling /usr/lib/git-core/git-commit with more flags.

Hypothetically imaging implementing this using cargo, calling cargo run -- commit is more concise than cargo run --bin git-commit -- -c some=flag.

@zimond

This comment has been minimized.

zimond commented Dec 5, 2016

If developing using VSCode, the RustyCode plugin requires only one binary to be specified. So I think this feature could be useful.

@huytd

This comment has been minimized.

huytd commented Feb 19, 2017

What is the status of this issue right now? It is very helpful if you have multiple binaries in a project!

@RalfJung

This comment has been minimized.

Member

RalfJung commented Jun 8, 2017

Should there also be a default test binary? Default bench binary?

I feel like test binaries are a very separate thing anyway, and cargo test per default runs all of them (right?). I never used bench, but it seems similar to test?

Does this interact with commands like cargo rustc and cargo rustdoc where the default takes precedence over other targets?
Does this interact with cargo install where the default is the only one installed unless otherwise specified?

I think this should affect cargo run only. It could be called "default-run" or so, like @andreastt suggested?

@sunjay

This comment has been minimized.

Member

sunjay commented Jul 25, 2017

What about something in the [[bin]] configuration like the following?

[[bin]]
name = "my-default-executable"
default = true

That fits into the existing way to configure binaries and will support future additions as well since it isn't as "one-off" as "default-run". :)

@mcobzarenco

This comment has been minimized.

mcobzarenco commented Nov 15, 2017

@sunjay I reckon @JanLikar's suggestion:

Do you think something like default-bin in [package] would be ok?

is preferable as it disallows in its representation having more than one default.

@GildedHonour

This comment has been minimized.

GildedHonour commented Jan 28, 2018

what's the status of this, is it already possible?

bors added a commit that referenced this issue Jul 16, 2018

Auto merge of #5710 - RalfJung:default-run, r=alexcrichton
implement default-run option to set default binary for cargo run

The implementation is not pretty but as good as I could make it. The fact that all this logic in `cargo_run` is for diagnosis only and essentially just re-implements the filtering done elsewhere really threw me off.

Fixes #2200

@bors bors closed this in #5710 Jul 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment