Skip to content

cargo-metadata always resolves features at the workspace level #7754

Open

Description

Problem
cargo-metadata appears to always resolve features at the "workspace" level, rather than for root crate. This means that cargo metadata will report features as enabled that aren't actually when cargo build is run in the same directory.

Steps

  1. Clone https://github.com/sfackler/rust-postgres
  2. Run cargo metadata --format-version 1 --manifest-path postgres-derive/Cargo.toml | jq '.resolve.nodes|.[]|select(.id|test("postgres-types"))'.
  3. Note that the entry for postgres-types has the derive and postgres-derive features enabled even though they are off by default for that crate. The postgres-derive-test crate in the same workspace enables that feature, which I assume is where that's coming from:
{
  "id": "postgres-types 0.1.0 (path+file:///home/sfackler/code/rust-postgres/postgres-types)",
  "dependencies": [
    "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
    "fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
    "postgres-derive 0.4.0 (path+file:///home/sfackler/code/rust-postgres/postgres-derive)",
    "postgres-protocol 0.5.0 (path+file:///home/sfackler/code/rust-postgres/postgres-protocol)"
  ],
  "deps": [
    {
      "name": "bytes",
      "pkg": "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
      "dep_kinds": [
        {
          "kind": null,
          "target": null
        },
        {
          "kind": null,
          "target": null
        }
      ]
    },
    {
      "name": "fallible_iterator",
      "pkg": "fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
      "dep_kinds": [
        {
          "kind": null,
          "target": null
        },
        {
          "kind": null,
          "target": null
        }
      ]
    },
    {
      "name": "postgres_derive",
      "pkg": "postgres-derive 0.4.0 (path+file:///home/sfackler/code/rust-postgres/postgres-derive)",
      "dep_kinds": [
        {
          "kind": null,
          "target": null
        }
      ]
    },
    {
      "name": "postgres_protocol",
      "pkg": "postgres-protocol 0.5.0 (path+file:///home/sfackler/code/rust-postgres/postgres-protocol)",
      "dep_kinds": [
        {
          "kind": null,
          "target": null
        },
        {
          "kind": null,
          "target": null
        }
      ]
    }
  ],
  "features": [
    "derive",
    "postgres-derive"
  ]
}

Possible Solution(s)
cargo metadata should respect the root crate when resolving the crate graph.

Notes

Output of cargo version: cargo 1.41.0-nightly (19a0de2 2019-12-12)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilationArea: features — conditional compilationC-bugCategory: bugCategory: bugCommand-metadataS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: 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