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 add should warn on binary crates #11803

Open
ghost opened this issue Mar 5, 2023 · 5 comments
Open

cargo add should warn on binary crates #11803

ghost opened this issue Mar 5, 2023 · 5 comments
Assignees
Labels
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` Command-add E-medium Experience: Medium S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.

Comments

@ghost
Copy link

ghost commented Mar 5, 2023

Problem

It was suggested that I should open this issue. Currently if you try to add a binary crate, it allows you to do that:

cargo add gitoxide

when it should probably fail, or at least warn the user that this is not something they should be doing.

Proposed Solution

No response

Notes

No response

@ghost ghost added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Mar 5, 2023
@narayan-krishna
Copy link

OP are you planning to tackle this? Can I claim it?

@ghost
Copy link
Author

ghost commented Mar 6, 2023

@narayan-krishna I would like to work on it, but I am quite busy. If you have time you are welcome to work on it 😊

@narayan-krishna
Copy link

Awesome! Would love to! @rustbot claim

@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. Command-add labels Mar 6, 2023
@epage
Copy link
Contributor

epage commented Mar 6, 2023

Note that the fix for this is not straight forward.

cargo add is relying solely on the Index. This has a limited set of data. There other issues that would benefit from having more data in the Index, like rust-lang/crates.io#5882 (which also links out to others). We'd likely need to do some planning before moving forward with adding this to the Index to make sure it handles the different needs.

It could be worked around by, at the end of cargo add, causing the relevant crates to be downloaded if we aren't in offline mode like a cargo check would and then use the other code within cargo to determine if a [lib] is present in the crate. The cargo install code (src/cargo/ops) is most similar to this as we error if there are no bins so hunting through that code will most likely yield what you need for this.

@narayan-krishna
Copy link

Understood, I'll then look into how the cargo install binary checks works, and repurposing it to look for libs (if it's necessary while the Index changes are being planned out)

@weihanglo weihanglo added the S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. label Jun 2, 2023
@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. E-medium Experience: Medium and removed S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. labels Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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` Command-add E-medium Experience: Medium S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.
Projects
None yet
Development

No branches or pull requests

3 participants