Skip to content

An option to disable default-features crate and workspace wide #14866

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

Open
jaskij opened this issue Nov 28, 2024 · 1 comment
Open

An option to disable default-features crate and workspace wide #14866

jaskij opened this issue Nov 28, 2024 · 1 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.

Comments

@jaskij
Copy link

jaskij commented Nov 28, 2024

Problem

I see value in minimizing the dependency tree - only bring in what I actually use.

The problem is that, between me using workspaces and features being additive, this creates a lot of noise in my manifest files, making them much harder to read.

As an example:

A small project I'm working on now, a set of three connected libraries in a workspace. There is a total of seven external non-dev dependencies, plus one or two intra-workspace ones. A total of around three thousand lines of Rust. default-features = false is found an astonishing twenty six times among the four manifest files.

I am most definitely not the only person doing this, as cargo-deny has a ban for default-features

To show what it looks like:

[dependencies]
bytes = { workspace = true, default-features = false }
num_enum = { workspace = true, default-features = false }
thiserror = { workspace = true, default-features = false }

futures = { workspace = true, default-features = false, optional = true }
tokio = { workspace = true, default-features = false, features = ["macros"], optional = true }
tokio-util = { workspace = true, default-features = false, optional = true }
valuable = { workspace = true, default-features = false, optional = true }

Proposed Solution

I would like an option that would allow me to, in one place, set default-feature = false for every dependency in the file manifest. Ideally, this would be three switches: separately for regular, dev and build dependencies.

The big issue I see with such an addition is that it does not fit within the existing structure of the manifest file - the obvious place to put it would be under dependencies, but that would create a precedent of Cargo itself reserving crate names, which I do not think is a good idea.

Other top level keys have their own roles, and adding this feature to them would not be suitable.

Just about the only option I see is adding a new top-level key to the manifest, perhaps one generally involved with governing default features. This option would be added under it.

Notes

#3126 may be relevant to this discussion.

@jaskij jaskij 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 Nov 28, 2024
@Nemo157
Copy link
Member

Nemo157 commented Dec 6, 2024

I've long wanted this ability too, syntax I've considered in the past was

[dependencies]
"*" = { default-features = false }

* is not a XID compatible identifier so shouldn't cause any conflicts, and should be relatively obvious (though it doesn't look great with the quoting).

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