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

Cargo metadata includes unused crates #10384

Closed
arlyon opened this issue Feb 12, 2022 · 5 comments
Closed

Cargo metadata includes unused crates #10384

arlyon opened this issue Feb 12, 2022 · 5 comments
Labels

Comments

@arlyon
Copy link

arlyon commented Feb 12, 2022

Problem

Hello!

I am working on arlyon/async-stripe which uses tarpaulin for coverage tracking. I recently introduced the tracing crate to clean up the logging story, whose MSRV is 1.49.0 (same at the library). However, the MSRV of a transitive dependency, valuable, is 1.51.0 because it uses the new resolver. Now, valuable is not actually included in the build (as evidenced by cargo tree -i valuable) because it is disabled by default, but cargo metadata fails:

❯ cargo metadata        
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
error: failed to download `valuable v0.1.0`

Caused by:
  unable to get packages from source

Caused by:
  failed to parse manifest at `/home/arlyon/.cargo/registry/src/github.com-1ecc6299db9ec823/valuable-0.1.0/Cargo.toml`

Caused by:
  feature `resolver` is required

  this Cargo does not support nightly features, but if you
  switch to nightly channel you can add
  `cargo-features = ["resolver"]` to enable this feature

My question / bug report is:

  • does it make sense to report metadata about crates that are not being built
  • if it does, can we support a flag to filter out those we don't want to include?

It feels strange having to bump my MSRV because of an unused optional transitive dependency breaking CI.

Steps

  1. Create a project with rust 1.49.0: cargo +1.49.0 new metadata-repro
  2. Add tracing-subscriber to your project: cargo +1.49.0 add tracing-subscriber
  3. Run: cargo metadata: cargo +1.49.0 metadata

Possible Solution(s)

Assuming omitting the data for unused features is a breaking change, consider providing a flag such that only the dependencies actually used by your program are emitted.

Notes

No response

Version

cargo 1.49.0 (d00d64df9 2020-12-05)
release: 1.49.0
commit-hash: d00d64df9f803bf5bba8714ca498d8f9159d07f6
commit-date: 2020-12-05
@ehuss
Copy link
Contributor

ehuss commented Feb 27, 2022

Hm, I'm not quite seeing the issue with tracing. Can you say which version you have, or more detail on how to reproduce?

~/Temp> cargo +1.49.0 new foo
     Created binary (application) `foo` package
~/Temp> cd foo
~/Temp/foo> cargo add tracing
    Updating 'https://github.com/rust-lang/crates.io-index' index
      Adding tracing v0.1.31 to dependencies
~/Temp/foo> cargo +1.49.0 metadata
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
    Updating crates.io index
{"packages":…}

I also don't see valuable in tracing's dependency tree.

@arlyon
Copy link
Author

arlyon commented Mar 1, 2022

Hi! Thanks for taking a look! :) Sorry, my bad, seems it is tracing-subscriber that triggers this issue, not tracing. I have updated the repro instructions.

@ehuss
Copy link
Contributor

ehuss commented Mar 1, 2022

Ah, I see. The issue is that tracing-core has [target."cfg(tracing_unstable)".dependencies.valuable]. cargo metadata needs to download the package in order to display the package information in the "packages" array. It is normal behavior for cargo metadata to include all packages that could potentially be used.

This can be avoided by using the --filter-platform option to limit which targets are included. Otherwise, I can't think of a way to avoid this issue. The only thing I can think of is for cargo to have first-class support for "unstable" features that would avoid the need for using the cfg(tracing_unstable) expression.

@arlyon
Copy link
Author

arlyon commented Mar 2, 2022

I will have a look at the possibility of having tarpaulin potentially use the filter-platform flag. Thank you for the insight :)

@epage
Copy link
Contributor

epage commented Oct 11, 2023

Looking over this, I'm not seeing any remaining action items (or opportunities to avoid this confusion in the future), so I'm going to close this. If there is a reason we should re-open it, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants