Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package spec in build plan and metadata? #7267

Closed
Hoverbear opened this issue Aug 19, 2019 · 2 comments · Fixed by #12914
Closed

Package spec in build plan and metadata? #7267

Hoverbear opened this issue Aug 19, 2019 · 2 comments · Fixed by #12914
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata

Comments

@Hoverbear
Copy link

Describe the problem you are trying to solve

I'd like to selectively prebuild some or all of the dependencies of my crate.

I can do this with cargo build --package log which is super awesome.

If I have two version of log, I need to specify which one with a package spec. Cargo gives me the ability to do cargo metadata and cargo build --build-plan, it also gives me the option to get an ID with cargo pkgid (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html)

Unfortunately, I can't make them play together. metadata and --build-plan don't provide package specs, so I end up forced to do manual parsing if I want to hope to make all these tools interact.

Describe the solution you'd like

Include a package spec in the output of cargo metadata and/or cargo build --build-plan

Notes
Related to #2644 since that was essentially what I was trying to do.

@Hoverbear Hoverbear added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Aug 19, 2019
@epage
Copy link
Contributor

epage commented Apr 21, 2022

If #7289 isn't a duplicate, then its closely related.

EDIT: #7289 is about adding PackageId to another struct, not about allowing integration with PackageIdSpec

@epage
Copy link
Contributor

epage commented Nov 3, 2023

Hmm, it appears package specs are ambiguous and we'd need to solve that first.

While working to improve the design of package id specs, we should include resolving #7725.

epage added a commit to epage/cargo that referenced this issue Nov 3, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Nov 7, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Nov 7, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 6, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 8, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 8, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 12, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 12, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 12, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 13, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 13, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 15, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 15, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 18, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Dec 28, 2023
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Jan 3, 2024
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
epage added a commit to epage/cargo that referenced this issue Jan 8, 2024
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
bors added a commit that referenced this issue Jan 15, 2024
fix(metadata): Stabilize id format as PackageIDSpec

### What does this PR try to resolve?

For tools integrating with cargo, `cargo metadata` is the primary interface.  Limitations include:
-  There isn't an unambiguous way to map a package entry from `cargo metadata`  to a parameter to pass to other `cargo` commands.  An `id` field exists but it is documented as an opaque string, useful only for comparisons with other `id`s within the document.
- There isn't an unambiguous way of taking user parameters (`--package`) and mapping them to `cargo metadata` entries.  `cargo pkgid` could help but it returns a `PackageIdSpec` which doesn't exist within the `cargo metadata` output.

This attempts to solve these problems by switching the `id` field from `PackageId` to `PackageIdSpec` which is a [publicly documented format](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html), can be generated by `cargo pkgid`, and is accepted by most commands via the `--package` flag.

As the `"id"` field is documented as opaque, this technically isn't a breaking change though people could be parsing it.

For `cargo_metadata` they do [use a new type that documents it as opaque but publicly expose the inner `String`](https://docs.rs/cargo_metadata/latest/cargo_metadata/struct.PackageId.html).  The `String` wasn't publicly exposed due to a request by users but instead their `PackageId` type replaced using `String`s in the API in oli-obk/cargo_metadata#59 with no indication given as to why the `String` was still exposed.  However, you'll note that before that PR, they had `WorkspaceMember` that parsed `PackageId`.  This was introduced in oli-obk/cargo_metadata#26 without a motivation given.

**Note that `PackageIdSpec` has multiple representation that might uniquely identify a package and we can return any one of them.**

Fixes #7267

### How should we test and review this PR?

### Additional information

cc `@oli-obk`
@bors bors closed this as completed in 63bb70d Jan 15, 2024
stupendoussuperpowers pushed a commit to stupendoussuperpowers/cargo that referenced this issue Feb 28, 2024
This makes it so you can take a package from `cargo metadata` and
then pass it with the `--package` option without worrying about
ambiguity.

Fixes rust-lang#7267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants