-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
contrary to manifest, cargo does not build src/bin/*.rs when toml contains [[bin]] #4013
Comments
Place thumbs-up/down votes for option 2 (modify cargo behavior) here. |
Ah yes the docs definitely at least need to be updated! The current behavior is intentional in the sense that it wasn't just an accident, but I'd be open to extending it as well if possible! |
Excellent. I'm happy to work on this. Will submit a PR to update the docs before next Monday, and then start working on a PR for option 2. |
Awesome thanks! Let me know if you need any help. Note that there are backwards compatibility concerns with option 2 above, so we may want to dig into those before jumping to a PR |
Update docs: cargo does not build src/bin/*.rs when toml contains [[bin] Update docs per #4013. Does it make sense to also mention this behavior in the [Configuring a target](http://doc.crates.io/manifest.html#configuring-a-target) section?
Now that the manifest is updated, what are the backward compatibility concerns? The only issue I see (off the top of my head) is some users may not want to autobuild
Case for opt-out automatic building:
Case for opt-in automatic building:
Is there a mechanism in place to patch existing Cargo.toml's with |
Yeah that's basically my worry, for example Cargo itself has We could perhaps add |
Sounds great. I imagine we'll want to also update One last consideration before I start work on the opt-in approach, because this plan should work for either opt-in or opt-out.
I'm not certain about (4), because anyone who neglects a project for a long period will be in for a surprise when they decide to dig into the project again, and nothing builds. Adding a FAQ for " |
cc @rust-lang/cargo Those steps sound reasonable to me @boxofrox (modulo bikeshedding and such), I'm cc'ing some others to see if they've got thoughts on the transition strategy here or whether we should do this. |
I'd like to brainstorm to see if we can't find a solution that doesn't involve exposing another flag to users (at least permanently). It seems like the case we're trying to avoid breaking is that only one file in This would still require a migration path most likely that might involve a flag for a while, but in the long term it would be automatically. Possibly it could annul the need for a |
👍 for this. In particular, I think that the original use case of "I want That is, for the layout
Cargo, without any configuration, infers two binaries: |
@matklad Yes exactly! I got hung up on figuring out what the root file of Then if cargo were to migrate to |
Huh, I've found at lest one repository that follows this convention: https://github.com/matklad/learnOpenGL/blob/master/Cargo.toml 😜 |
Oh note that this isn't just related to the case of one binary having submodules, but also a case that sometimes you want to configure one |
@alexcrichton indeed! Split off #4086 because it seems orthogonal to this issue (although it makes it less pressing), and is a nice quality of life improvement. I don't think it's possible to make However, I am not sure that the current multi-staged plan will be executed properly to the end, and that we won't get stuck in the middle, with both a wrong default, a configuration option, and broken old crates! I think we need a more rigid process for removing deprecated stuff from Cargo and switching defaults, rust-lang/rfcs#1953 perhaps? |
I do like #4086. Initially, I imagined a couple use cases:
However, I could just split my project up into a lib crate, daemon crate, and crate of misc binaries to achieve the same. Or I could just use a shell script to |
Yeah, what I want to do is migrate to continue to infer the binaries, but that in the final state (and I realize this may involve epochs and such) we should not expose a flag to change that behavior back to the current behavior.
To clarify: cargo has only one binary, all the other files in the bin directory are submodules of it. The problem cargo's dealing with is that cargo build would always fail because it would try to build modules that aren't binaries. I think users who want to only build one binary but have multiple can suffice with |
🤦♂️ Thanks for clarifying. Striking that comment from my post, so no one else is confused by it. |
With #5330 shipped is there more left to do here? |
Indeed I think this is fixed! |
According to http://doc.crates.io/manifest.html#the-project-layout...
... which is presented as an invariant. There is no mention that this is conditional.
My project started out with with a few binaries
src/bin/*.rs
. Whensrc/bin/daemon.rs
ballooned, I refactored it intosrc/bin/daemon/main.rs
and organized extracted code into modules undersrc/bin/daemon
.Once I added a
[[bin]]
entry toCargo.toml
,cargo build
only builds the daemon binary, and no longer adheres to the quote above.I see two options here:
Update the quoted portion of the manifest to indicate that *Cargo will treat any files located in
/src/bin/*.rs
as executables unless the toml contains a[[bin]]
section.Modify the behavior of
cargo
to comply with the docs.cargo
treats any files located insrc/bin/*.rs
that are not otherwise defined in a[[bin]]
section as executables.a.
cargo
fetches list of binaries fromsrc/bin/*.rs
.b.
cargo
replaces any binaries fromsrc/bin/*.rs
with respective[[bin]]
entries found in toml.c.
cargo
builds all executables in said list.The text was updated successfully, but these errors were encountered: