cargo-metadata always resolves features at the workspace level
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
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
- Clone https://github.com/sfackler/rust-postgres
- Run
cargo metadata --format-version 1 --manifest-path postgres-derive/Cargo.toml | jq '.resolve.nodes|.[]|select(.id|test("postgres-types"))'. - Note that the entry for
postgres-typeshas thederiveandpostgres-derivefeatures enabled even though they are off by default for that crate. Thepostgres-derive-testcrate 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 (19a0de242 2019-12-12)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior in the rust-postgres workspace with the documented cargo metadata command, then compare its feature resolution with cargo build for postgres-derive/Cargo.toml. Trace Cargo's workspace and root-crate metadata resolution entry points; done means metadata reports only features enabled for the selected root crate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100