-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Make cargo --list
print description for custom subcommands
#10662
Comments
As proof of concept, I have released a version of the |
Currently, cargo hard codes the descriptions for first-party cargo external subcommands like |
The Cargo Team discussed this a bit, and here are some questions or thoughts from that discussion:
|
I was thinking that I'd missed something in the documentation, but I see that this issue is still open. Hopefully it should be resolved sometime in the near future. |
Perhaps we could try and embed a subcommand's description into the executable as discussed, at least for the platforms which support doing this, and as a fallback for other platforms or executables without a description embedded, try to fetch it from another source (perhaps from |
Instead of doing a web request on every |
Compared to putting descriptions into the executable, putting descriptions in .crates2.json has the disadvantage that it would only work for subcommands installed using As a fallback for the cases where the executable does not contain a description, using descriptions from .crates2.json seems good to me. |
#13847 was proposing downloading descriptions from crates.io for plugins installed via But yes, it doesn't cover other install cases. Its also a lot lower barrier for adoption than accepting the embedded description scheme. |
I think this is out of scope. But then again, one could alert the devs of |
Web requests might lead to wrong information. People can have a script called To me, embedded description is more accurate an approach, and then description-in-crates2.json. Despite that, it depends on how accurate |
Perhaps the following logic could be implemented to solve most of the aforementioned issues:
|
For myself, I don't see enough benefit to doing this. |
Problem
Currently
cargo --list
prints descriptions only for the builtin subcommands. For third-party subcommands likecargo expand
it does not print a description.Proposed Solution
First of all, I don't want
cargo --list
to run any of the binaries (in order to, for example, run--help
on them and parse the output, or some other handshake to cause the binary to print out a description of itself). Arbitrary binaries in the PATH are not necessarily safe to run. An arbitrary binary might completely ignore--help
or any other handshake being passed by Cargo, and immediately do unwanted stuff instead, which would be unexpected and undesirable to the person runningcargo --list
.Instead, Cargo subcommands should be able to embed a description into their compiled binary, which can then be directly retrieved from the binary by Cargo in a way that does not involve running it.
The way this is exposed to subcommands can be as simple as:
The underlying implementation would need to be platform-specific based on the file format used for executables on the platform. On platforms that use ELF executables, I would propose that this uses a Note. On those platforms the macro shown above would expand to:
This note can then be retrieved efficiently from the ELF executable during
cargo --list
by using theobject
crate to parse the executable's program header.From testing on my machine with the
cargo-expand
crate,cargo build --release
produces a 13 MB executable, and retrieving the subcommand description ELF note from it using theobject
crate takes 0.03 milliseconds, so this should be plenty fast enough forcargo --list
.We do not necessarily need to implement support for a large number of platforms immediately up front. Supporting just ELF would already benefit a large fraction of Cargo users.
Notes
Yes, exactly.
The text was updated successfully, but these errors were encountered: