Skip to content
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

cargo -h is misleading when building multiple bin with a src/main.rs #3115

Closed
Cobrand opened this issue Sep 25, 2016 · 7 comments · Fixed by #6631
Closed

cargo -h is misleading when building multiple bin with a src/main.rs #3115

Cobrand opened this issue Sep 25, 2016 · 7 comments · Fixed by #6631
Assignees
Labels

Comments

@Cobrand
Copy link

Cobrand commented Sep 25, 2016

if you have

src/
    main.rs
    bin/
        other_bin.rs
        other_bin2.rs

cargo run will say that it requires that a project have one executable, "use the --bin option to specify which one to run".

However cargo -h clearly says that cargo run "Build and execute src/main.rs"

So why should I have to specify --bin if I want to build src/main.rs ? Is this the intended behaviour ? If it isn't, well it's probably a bug. If it is, maybe some rewording in cargo -h will help, and maybe add an option in Cargo.toml along "[[bin]]" which would allow you to say which bin is built by default (like a field default = true). I think that no matter how many binaries you have, if you have a src/main.rs, it should build that by default.

@alexcrichton
Copy link
Member

Ah sounds like it should the small docs there should be updated!

@alexcrichton alexcrichton added the A-documenting-cargo-itself Area: Cargo's documentation label Sep 26, 2016
@Cobrand
Copy link
Author

Cobrand commented Sep 27, 2016

I'm fine with this being a doc problem, but should cargo behave that way ? I don't think it makes much sense that someone has to type cargo run --bin crate-name when there is an explicit src/main.rs in the crate and everything else is in src/bin/. If I wanted to be explicit about it, I would have moved everything in src/bin/.

I personally think it makes more sense to run by default src/main.rs even though other binaries' mains are in src/bin/; is there a reason for it not being like that ?

@alexcrichton
Copy link
Member

To Cargo at least any bin target is the same as the other, whether it's src/main.rs or src/bin/foo.rs they're treated equally

@Cobrand
Copy link
Author

Cobrand commented Sep 27, 2016

Is this because of technical reasons (like, it was the easiest way to implement this) or because someone decided that it would explicitly be like that because of some X reason ?

If the latter, I think I will submit a PR at some point in the future allowing to compile src/main.rs when running only cargo run. If this PR isn't allowed, I'll do another one allowing a field "default" under [[bin]] allowing it to be run by default when no --bin <bin_name> is specified. Does that look ok ?

@alexcrichton
Copy link
Member

This basically just fell out of the initial implementation. It wasn't really decided either for or against.

@rust-lang/tools, thoughts about this issue?

@Cobrand
Copy link
Author

Cobrand commented Sep 30, 2016

Since there are no objections, I take it that any PR about this issue won't be closed right away ?

@alexcrichton
Copy link
Member

I might recommend holding off on sending a PR just yet until we get some more opinions. I'd personally at least prefer to treat all binaries as equal as opposed to making some special over others.

@dwijnand dwijnand self-assigned this Feb 4, 2019
bors added a commit that referenced this issue Feb 5, 2019
@bors bors closed this as completed in #6631 Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants