Skip to content

Warn if dependency doesn't have library target kind #6702

New issue

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

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

Already on GitHub? # to your account

Closed
jethrogb opened this issue Feb 28, 2019 · 7 comments · Fixed by #9771
Closed

Warn if dependency doesn't have library target kind #6702

jethrogb opened this issue Feb 28, 2019 · 7 comments · Fixed by #9771
Assignees
Labels
A-crate-dependencies Area: [dependencies] of any kind A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy

Comments

@jethrogb
Copy link
Contributor

jethrogb commented Feb 28, 2019

When specifying a crate without a library target kind as a dependency, cargo currently just silently ignores it. For example:

[package]
name = "deptest"
version = "0.1.0"
edition = "2018"

[dependencies]
ripgrep = "*"
$ cargo run
   Compiling deptest v0.1.0 (/tmp/deptest)
    Finished dev [unoptimized + debuginfo] target(s) in 0.31s
     Running `target/debug/deptest`
Hello, world!

Note that the dependency isn't even compiled. Clearly, Cargo has already decided to elide this crate in the dependency graph, but the cause is not obvious to the user. All this can be confusing if the user is expecting to be able to use the dependency. I think a warning message is in order.

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

lukaslueg commented Feb 28, 2019

I concur that this is confusing and should result in a warning (especially since there usually is ripgrep and libripgrep and such). Two use cases that are probably legitimate:

  • An "empty" dependency still means "A solution to my dependency graph exists. Prove me wrong!"
  • Docs are pulled in unless --no-deps is supplied.

@ehuss ehuss added A-crate-dependencies Area: [dependencies] of any kind A-diagnostics Area: Error and warning messages generated by Cargo itself. labels Apr 6, 2020
@ehuss ehuss added the E-easy Experience: Easy label Jun 21, 2021
@MonliH
Copy link
Contributor

MonliH commented Jun 22, 2021

I'd be interested in implementing this.

@rustbot claim

@MonliH
Copy link
Contributor

MonliH commented Jul 19, 2021

Unfortunately, I no longer have the time to work on this.

@rustbot release-assignment

@0xPoe
Copy link
Member

0xPoe commented Jul 25, 2021

@rustbot claim

@0xPoe
Copy link
Member

0xPoe commented Aug 2, 2021

@ehuss I'm trying to add this warning, but I can't find anywhere to add it when resolving dependencies. Could you help with some hints?

@ehuss
Copy link
Contributor

ehuss commented Aug 2, 2021

Hm, I'm not sure exactly where would be the best place.

Essentially, it needs to iterate over the workspace member IDs, call resolve.deps(member_id), iterate over those dependencies and fetch the package object for each one (pkg_set.get_one(dep_id)), and call if !dep_pkg.targets().iter().any(|t| t.is_lib()) { /*warn*/ }.

There are a few places where it could do that. I think one place would be the bottom of resolve_ws_with_opts. That is a common place where resolution is done. Another place would be in create_bcx. That is where all the build commands create their build graph. A drawback of create_bcx is that would only warn on build commands, and not others. I'm not sure if that matters much.

@0xPoe
Copy link
Member

0xPoe commented Aug 7, 2021

Hm, I'm not sure exactly where would be the best place.

Essentially, it needs to iterate over the workspace member IDs, call resolve.deps(member_id), iterate over those dependencies and fetch the package object for each one (pkg_set.get_one(dep_id)), and call if !dep_pkg.targets().iter().any(|t| t.is_lib()) { /*warn*/ }.

There are a few places where it could do that. I think one place would be the bottom of resolve_ws_with_opts. That is a common place where resolution is done. Another place would be in create_bcx. That is where all the build commands create their build graph. A drawback of create_bcx is that would only warn on build commands, and not others. I'm not sure if that matters much.

Thanks for your help! Created a PR for it.

@bors bors closed this as completed in 491deb6 Aug 23, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-crate-dependencies Area: [dependencies] of any kind A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants