-
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
Unable to use a feature of an optional dependency from a feature #3494
Comments
Yes it's true that relying on |
To chime in. There is a push in Anyways. Since the new type definition is feature gated by |
Just a friendly heads up from #7259 - this problem is hitting gfx-rs ecosystem quite badly. We want things like |
libstd itself also hit an annoying instance of this. |
Over in #7259, @est31 proposed the following backwards-compatible syntax for "enable this feature of that dependency only if the dependency is otherwise enabled": |
When we introduced the `rustls` feature, we did it like this: ```toml [features] proxy = ["hyper-proxy"] rustls = ["hyper-proxy/rustls", "tokio-rustls", "hyper-rustls"] tls = ["hyper-proxy/tls", "native-tls", "tokio-tls", "hyper-tls"] ``` A problem is hidden here: enabling an optional dependency's feature enabled the dependency. Because of this, `hyper-proxy` is already being downloaded and compiled, even if `proxy` isn't enabled: ``` $ cargo c … Checking hyper-proxy v0.6.0 Checking tbot v0.5.1 (…) ``` But to be able to use it, you have to enable the `proxy` feature, which seems odd. Since cargo doesn't provide a way to enable an optional dependency's feature without enabling the dependency (at least yet; rust-lang/cargo#3494), I think that it's better to always provide proxy functionality.
Just my 2 cents. Alternatively, this could be solved if the following syntax is supported. The same syntax will also address #1839. [features]
default = ["std"]
std = []
[target.'cfg(feature = "std")'.dependencies]
serde = { version = "*", optional = true }
[target.'cfg(not(feature = "std"))'.dependencies]
serde = { version = "*", optional = true, default-features = false } |
* primitive-types: add no_std support for serde feature This adds no_std support to primitive-types with serde. Due to rust-lang/cargo#3494, a separate new feature `serde_no_std` is created. * primitive-types: update changelog * travis: add tests for primitive-types
This enables serde crates themselves. Related cargo issue: rust-lang/cargo#3494
This enables serde crates themselves. Related cargo issue: rust-lang/cargo#3494
I just ran into this myself, and would like to see a solution as well. @xu-cheng I would love to see that syntax work. |
That syntax feels rather verbose for what I think is the common case (" [features]
default = ["std"]
std = ["?create/std"]
serde = ["?create/serde"] Now we need to specify the |
Just ran into this issue as well. FWIW, I think the |
Seems I opened a "Pre-Pre-RFC" thread about this same problem: https://internals.rust-lang.org/t/pre-pre-rfc-weak-cargo-feature-activation/13141/1 I also like the |
thanks @ehuss for getting the ball rolling on this! |
Tracking issue: #8832 |
For example lets say we use
and we want to use the std feature of serde if it is used.
But now if someone wants to use our std feature serde WILL be imported. If I would want to represent this I would write
Right now it's impossible to use a feature of an optional dependency from an own feature without forcing it to be used.
The text was updated successfully, but these errors were encountered: