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

Cargo accepts conditional dependencies based on feature, but documented not to #7442

Closed
jsgf opened this issue Sep 26, 2019 · 4 comments
Closed
Labels
A-cfg-expr Area: Platform cfg expressions A-target-dependencies Area: [target.'cfg(foo)'.dependencies] C-bug Category: bug

Comments

@jsgf
Copy link
Contributor

jsgf commented Sep 26, 2019

Problem
According to the Cargo documentation:

Unlike in your Rust source code, you cannot use [target.'cfg(feature = "my_crate")'.dependencies] to add dependencies based on optional crate features. Use the [features] section instead.

However, the tracing crates are apparently doing this successfully:

[target.'cfg(not(feature = "std"))'.dependencies]
spin = "0.5"
lazy_static = { version = "1", features = ["spin_no_std"] }

I would expect this to fail.

Possible Solution(s)
It's not clear to me whether the code or the documentation is correct.

I encountered this because I'm writing tools to process Cargo metadata which understands platform-specific dependencies, and it failed on encountering a dependency predicated on a feature. I'm not sure if I should implement support for that or not.

Notes

Output of cargo version:
cargo 1.37.0 (9edd089 2019-08-02)

@ehuss
Copy link
Contributor

ehuss commented Sep 26, 2019

That expression is always true, so it is essentially always on, it looks to be a mistake.

Cargo could maybe display a warning about this, though? I'm not sure, because one can say RUSTFLAGS='--cfg feature="std"', which will enable it. But that seems somewhat unusual.

@ehuss ehuss added A-cfg-expr Area: Platform cfg expressions A-target-dependencies Area: [target.'cfg(foo)'.dependencies] labels Sep 26, 2019
@jsgf
Copy link
Contributor Author

jsgf commented Sep 26, 2019

@ehuss Ok, so in that context cfg(feature = "foo") will always evaluate to false? Does that apply to any unsupported predicate?

@ehuss
Copy link
Contributor

ehuss commented Sep 26, 2019

I believe so. If it is not in the output of rustc --print=cfg $RUSTFLAGS, then it is false.

@ehuss
Copy link
Contributor

ehuss commented Dec 13, 2019

Closing as warnings are now emitted via #7660.

@ehuss ehuss closed this as completed Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cfg-expr Area: Platform cfg expressions A-target-dependencies Area: [target.'cfg(foo)'.dependencies] C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants