cargo metadata supports artifact dependencies#11550
Conversation
|
r? @ehuss (rustbot has picked a reviewer for you, use r? to override) |
09ec414 to
1111831
Compare
dtolnay
left a comment
There was a problem hiding this comment.
I implemented support for this in reindeer (dtolnay-contrib/reindeer@6ba7df1) and it works for my use case. 👍
| /// What the manifest calls the crate. | ||
| /// | ||
| /// A renamed dependency will show the rename instead of original name. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| extern_name: Option<InternedString>, |
There was a problem hiding this comment.
Should this always be set? Related to deps.name being marked "deprecated", if this is None, then there would not be a way to determine the name of the dependency?
There was a problem hiding this comment.
I believe so. Update with d827e47.
⚠️ Potential breaking change ⚠️
However, previously cargo-metadata allows a dependency with different renamed co-exist. Its resolve.nodes.deps then will miss that dependency,
which is wrong I believe. After d827e47, cargo-metadata starts erroring out for that situation. That will introduce a "breaking change" to cargo-metadata, so I made 90044d1 to ignore that kind of error to keep the old behavior. If we're happy to ship this breaking change, 90044d1 can be reverted.
There was a problem hiding this comment.
I'm fine with generating an error in that case. It's an error for a normal build, so I wouldn't consider it a valid configuration.
There was a problem hiding this comment.
Oh crud, I think I misunderstood this. The extern_name is only relevant for artifact dependencies, correct? If so, I think I would like to keep it gated on -Zbindeps (that is, extern_name should only be set when -Zbindeps is set). Sorry for the confusion and runaround.
I think in the longer term when stabilizing we'll set it unconditionally (and add the deprecation notice).
There was a problem hiding this comment.
Updated with d02e36c and rebased to make extern_name optional. Thanks for the review!
90044d1 to
d827e47
Compare
This refactor reuse the logic of `core::compiler::unit_dependencies::match_artifacts_kind_with_targets` to emit error if there is any syntax error in `ArtifactKind`. It also put `match_artifacts_kind_with_targets` to a better place `core::compiler::artifact`.
Previous, `cargo metadata` allows a dependency with different renamed co-exist. However, its `resolve.nodes.deps` will miss that dependency, which is wrong. After this commit, `cargo metadata starts erroring out for that situation.
d827e47 to
d02e36c
Compare
|
Thanks! Sorry again about my confusion. @bors r+ |
|
☀️ Test successful - checks-actions |
9 commits in 1cd6d3803dfb0b342272862a8590f5dfc9f72573..a5d47a72595dd6fbe7d4e4f6ec20dc5fe724edd1 2023-01-12 18:40:36 +0000 to 2023-01-16 18:51:50 +0000 - Add network container tests (rust-lang/cargo#11583) - Show progress of crates.io index update even `net.git-fetch-with-cli` option enabled (rust-lang/cargo#11579) - `cargo metadata` supports artifact dependencies (rust-lang/cargo#11550) - fix(docs): add required "inherits" option to example profile (rust-lang/cargo#11504) - add documentation that SSH markers aren't supported (rust-lang/cargo#11586) - Fix typo (rust-lang/cargo#11585) - Enable source_config_env test on Windows (rust-lang/cargo#11582) - Support `codegen-backend` and `rustflags` in profiles in config file (rust-lang/cargo#11562) - ci: reflect to clap updates (rust-lang/cargo#11578)
Update cargo 9 commits in 1cd6d3803dfb0b342272862a8590f5dfc9f72573..a5d47a72595dd6fbe7d4e4f6ec20dc5fe724edd1 2023-01-12 18:40:36 +0000 to 2023-01-16 18:51:50 +0000 - Add network container tests (rust-lang/cargo#11583) - Show progress of crates.io index update even `net.git-fetch-with-cli` option enabled (rust-lang/cargo#11579) - `cargo metadata` supports artifact dependencies (rust-lang/cargo#11550) - fix(docs): add required "inherits" option to example profile (rust-lang/cargo#11504) - add documentation that SSH markers aren't supported (rust-lang/cargo#11586) - Fix typo (rust-lang/cargo#11585) - Enable source_config_env test on Windows (rust-lang/cargo#11582) - Support `codegen-backend` and `rustflags` in profiles in config file (rust-lang/cargo#11562) - ci: reflect to clap updates (rust-lang/cargo#11578) r? `@ghost`
What does this PR try to resolve?
After this PR,
cargo metadatawill contain information of artifact dependencies in bothpackagesandresolve.nodes.deps.dep_kinds. The implementation follows this comment #9992 (comment).fixes #10607
How should we test and review this PR?
Raise some design decisions here:
resolve.nodes.deps.dep_kinds.compile_target, if the artifact dependency is specified as{ …, target = "target" }, it will show as"target": "<target>"since Cargo doesn't know the exact target triple at that time.dep_kindonto the arrayresolve.nodes.deps.dep_kinds.resolve.nodes.deps.dep_kinds.nameis deprecated. If a dependency doesn't have any lib target, it will show as empty string, e.g."name": "".Some integration tests:
metadata::workspace_metadata_with_dependencies_and_resolvereflects the change.metadata::cargo_metadata_with_invalid_artifact_depsverifies syntax error of artifactAdditional information
I might revisit #10407 after this to do clean-ups.