Skip to content

cargo metadata doesn't indicate that feature-enabled transitive platform-specific deps are platform-specific #9863

@illicitonion

Description

@illicitonion

Problem
If on one platform a crate enables a feature which enables a transitive dependency, and on another it doesn't, there's no way to capture this from the output of cargo metadata.

Steps

  1. In this repo run cargo metadata or cargo metadata --filter-platform=x86_64-unknown-linux-gnu. In this crate, serde's derive feature is enabled for x86_64-apple-darwin but not for x86_64-unknown-linux-gnu, which means it depends on serde-derive on x86_64-apple-darwin but not on x86_64-unknown-linux-gnu.
  2. Try to work out whether serde-derive should be built on x86_64-unknown-linux-gnu.
  3. Find that there's not enough information to determine this.

Possible Solution(s)

  1. We could populate DepKindInfo.target for these dependencies, such that they can be identified as platform-specific
  2. When running with --filter-platform for a non-matching platform, we could omit these dependencies. That may require callers to run cargo metadata multiple times and splice the results, which would be a bit unfortunate.

Notes

Output of cargo version: cargo 1.54.0 (5ae8d74b3 2021-06-22), also cargo 1.56.0-nightly (f559c109c 2021-08-26)

This issue makes it hard to translate crates.io packages for building with non-cargo build systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugCommand-metadataS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions