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

Different default features for crate binary and library #12054

Closed
emilk opened this issue Apr 28, 2023 · 3 comments
Closed

Different default features for crate binary and library #12054

emilk opened this issue Apr 28, 2023 · 3 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.

Comments

@emilk
Copy link

emilk commented Apr 28, 2023

Problem

I have a crate that is both a library and a binary. I want to be able to specify a default set of features for users of the library and the binary. For instance, people who write mycrate = "*" in their Cargo.toml get a small set of features (and fast compilation times), but when typing cargo install mycrate they get most or all of the features enabled.

This is currently not possible, due to the single [features] default = […] field in Cargo.toml.

Proposed Solution

The [lib] and [[bin]] sections already have a required-features = […] field. I propose we also add a default-features = […] field that, if present, will override the default field in [features]:

[package]
name = "mycrate"

[[bin]]
# Make most features opt-out for users of the binary
default-features = ["features", "that", "binary", "users", "often", "want"]

[lib]
default-features = [] # Make all features opt-in for users of the library

[[test]]
# We don't set `default-features` here, so the same features from `[features] default` are used


[features]
# default features for any target that hasn't set `default-features` (tests, examples and benches):
default = ["foo", "bar"]

Notes

No response

@emilk emilk added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Apr 28, 2023
@weihanglo
Copy link
Member

Thanks for the issue report.
RFC 3374 should cover the cargo install use case. This also looks like a duplicate of #10409.

@weihanglo
Copy link
Member

Close in favour of #10409. Thanks.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2023
@emilk
Copy link
Author

emilk commented May 1, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants