Skip to content

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

@jsgf

Description

@jsgf

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cfg-exprArea: Platform cfg expressionsA-target-dependenciesArea: [target.'cfg(foo)'.dependencies]C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions