-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add a general mechanism of setting RUSTFLAGS in Cargo for the root crate only #3310
Add a general mechanism of setting RUSTFLAGS in Cargo for the root crate only #3310
Conversation
I do think we should have a mechanism for this, but I think this option name would be confusing; it doesn't give any indication that it applies just to the root crate, or that it's different than RUSTFLAGS in any way. |
We have rustflags that impact ABI, and that would be unsound to only compile one crate with. For example, -Csoft-float on some targets, -Ctarget-feature (and -Ctarget-cpu by extension), and likely others (several -Z flags are this way, for sure). I think this RFC should have some consideration of this, which I don't see. |
Thanks for taking a look, I understand the concern and I'm fine to update the name of the option to make it clearer. Any thoughts on a suitable replacement? Thanks for the comment, this issue exists today in Cargo via the |
It's worth mentioning, but I wouldn't be too concerned about it - both setting rust_flags and setting ABI flags are advanced features and naive users are unlikely to stumble into an error here, so I'm fine with this being an 'at your own risk' kind of feature. The other side of the trade-off is that any mechanism for checking this sort of thing would need a list of 'risky' flags which would need to be kept in sync between rustc and Cargo, which is intrinsically fragile. More philosophically, the less Cargo knows about rustc, the better - separation of concerns and all that. |
In principal I agree, but it is worth noting This isn't to say that cargo should know about it, but just that it's not as much of an advanced-user feature as you suggest. |
… the root crate only.
…ags for only a single crate.
… details to the cargo toml alternative feature.
4432c71
to
9c5f01d
Compare
@ridwanabdillahi At the risk of making this slightly more complex: we have various things in Cargo for matching crates and setting profile information on them, and I'm wondering if we could use similar logic, so that it's possible to say "use these rustflags for this crate, and these rustflags for the top-level crate". |
@joshtriplett thanks for your response!
I believe this is possible via the The point of this RFC was to remove the need to specify a given profile when setting the rustflags that should be enabled for a given crate. This way any Rust developer that would like to set rustflags can regardless of the profile being used when running a build/test. I understand this RFC adds to the complexity of setting rustflags by adding yet another supported way that is drastically different from the existing scenarios, i.e. cargo cli option. There is also an alternative listed in the RFC of expanding on the already supported |
I agree. All the other options which have a) rename the flag to
To allow approach b) to support this I guess we could add another parameter to In general, I think none of this is impossible today - One could write a |
I don't have a strong preference on the bikeshed color for this. Anything like |
## --rustflags for a workspace | ||
|
||
Cargo supports two types of [workspaces](https://doc.rust-lang.org/cargo/reference/workspaces.html), a workspace with a root package and | ||
a workspace with a virtual manifest, meaning a "primary" package does not exist. | ||
|
||
For workspaces that contain a root package, any `--rustflags <RUSTFLAGS>` options set will be passed to the invocation of the Rust | ||
compiler for the root crate only. If the `workspace.default-members` manifest key has been set, then only the members listed as a | ||
default member will have the `--rustflags` values passed to the invocation of rustc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like tying the definition of "root package" to the primary package or the default-members doesn't seem like the right way to go.
Unfortunately, I'm not sure of anything else. Maybe "whatever is 'selected' on the command-line" which will be inferred from the primary package or default-members but allows a user finer control (cargo build --package foo
would make foo
a root for that invocation)
For workspaces that contain a root package, any `--rustflags <RUSTFLAGS>` options set will be passed to the invocation of the Rust | ||
compiler for the root crate only. If the `workspace.default-members` manifest key has been set, then only the members listed as a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some terminology is being mixed here. A "package" corresponds to a Cargo.toml
file while a "crate" is one build target within a package, whether that is the bin, the lib, an example, or one of the 20 integration test bins.
Which does raise the question of how this might want to be applied for different build target types.
@rfcbot fcp postpone Based on our discussion in today's Cargo team meeting, I'm proposed we postpone this RFC until someone can pick it up and drive it to completion. In particular, areas that need addressing
This runs into a bit of the same problem as There is some debate over whether a CLI flag or a config is better for this. The CLI flag might be easier to design. In the past though, there has been concern over the growth of Cargo's CLI and how that makes it less approachable. |
Team member @epage has proposed to postpone this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to postpone, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This is now postponed. |
This RFC adds support In Cargo for setting RUSTFLAGS via a new command line options,
--rustflags <RUSTFLAGS>
that only applies to the current crate being built.Rendered