I have a project that is using cargo's workspaces where the root is a bin crate. Running cargo clippy in the root folder causes error: no library targets found.
This seems to be because cargo metadata --no-deps lists every crate in the workspace e.g.
{
"packages":[
{
"name":"gl32",
"version":"0.0.1",
"id":"gl32 0.0.1 (path+file:///project/location/gl32)",
"license":null,
"license_file":null,
"source":null,
"dependencies":[ ],
"targets":[
{
"kind":[
"lib"
],
"name":"gl32",
"src_path":"/project/location/./gl32/src/lib.rs"
},
{
"kind":[
"custom-build"
],
"name":"build-script-build",
"src_path":"build.rs"
}
],
"features":{
},
"manifest_path":"/project/location/./gl32/Cargo.toml"
},
// <snip other sub-crates>
{
"name":"game",
"version":"0.1.0",
"id":"game 0.1.0 (path+file:///project/location)",
"license":null,
"license_file":null,
"source":null,
"dependencies":[ ],
"targets":[
{
"kind":[
"bin"
],
"name":"game",
"src_path":"/project/location/src/main.rs"
}
],
"features":{
"profile":[
],
"default":[
"profile"
]
},
"manifest_path":"/project/location/Cargo.toml"
}
],
///etc
And since the first one is a library crate it ends up invoking rustc with --lib instead of --bin. I'm not sure how this can be worked around.
I don't think this has anything to do with workspaces. The issue is simply that there's an assumption in cargo-clippy that the first crate in packages is the current crate. I've never seen this assumption broken so far, is your workspace uploaded somewhere so I can play around with it? I can't reproduce it locally, but I might not be creating the correct crate names and folder structure.
Unfortunately its a private project but I have reduced it so it will still cause this. If it makes a difference i'm running this on linux.
reduced.zip
I have a similar issue, which can be reproduced by replacing
# Explicit
[workspace]
members = [
"./gl32",
]
With
# Implicit
[workspace]
In the root Cargo.toml.
In the explicit case, running cargo clippy from the root directory fails with error: no library targets found, but running it from the gl32 directory works.
In the implicit case, the reverse occurs: cargo clippy from the root directory works and lint tests and examples, but running it from the gl32 directory fails with no example target named ....
Something has reintroduced this between v0.0.142 and v0.0.144. I suspect #1860.
Edit: Confirmed. Reverting 956a98c0c7efbc7bb7dda33a2179dccc336a1bdd makes it work in the workspace root again.
Is that regression fixed by #1896, too?
Yes, it's the same.
Most helpful comment
Unfortunately its a private project but I have reduced it so it will still cause this. If it makes a difference i'm running this on linux.
reduced.zip