Stream: general

Topic: add dependency when feature disabled


gnzlbg (Dec 05 2018 at 12:32, on Zulip):

Is there a way to make an optional dependency non-optional if a cargo feature is disabled ?

nagisa (Dec 05 2018 at 12:41, on Zulip):

@gnzlbg cargo features are expected to be additive, not negative

nagisa (Dec 05 2018 at 12:41, on Zulip):

a lot of stuff breaks if they are negative

gnzlbg (Dec 05 2018 at 12:43, on Zulip):

so that's the problem, say a crate wants to support no_std, and it adds a use_std feature enabled by default

gnzlbg (Dec 05 2018 at 12:43, on Zulip):

when it is disabled, the crate should be no_std, but for that it would like to use a no_std dependency that is not needed when std is available

gnzlbg (Dec 05 2018 at 12:44, on Zulip):

that is, "if use_std is not enabled, then add a dependency"

gnzlbg (Dec 05 2018 at 12:45, on Zulip):

if we need an additive feature to add the no_std dependency, we might just call that feature no_std, and we have added a negative feature

nagisa (Dec 05 2018 at 12:47, on Zulip):

teechnically you can do [dependencies.'anycfghere'.foo] IIRC

nagisa (Dec 05 2018 at 12:48, on Zulip):

[target.'cfg(not(use_std))'.dependencies.dep] for example...

nagisa (Dec 05 2018 at 12:49, on Zulip):

third try’s the charm ^)

gnzlbg (Dec 05 2018 at 12:51, on Zulip):

[target.cfg(not(feature = "use_std")).dependencies.dep] should work indeed

nagisa (Dec 05 2018 at 12:53, on Zulip):

Somehow I have a sinking feeling that I’ve recommended a similar thing before but it turned out that cargo has a white/blacklist of supported cfgs and only allows very limited subset of cfgs :D

gnzlbg (Dec 05 2018 at 13:01, on Zulip):

@nagisa https://github.com/rust-lang/cargo/issues/1839

gnzlbg (Dec 05 2018 at 13:01, on Zulip):

yep, that doesn't work

Last update: Nov 20 2019 at 11:30UTC