clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
14.14k stars 1.03k forks source link

Generate shell completions as part of the build process to assist cross compilation #5562

Closed Flowdalic closed 2 months ago

Flowdalic commented 3 months ago

Please complete the following tasks

Clap Version

4.5.8

Describe your use case

Gentoo currently improves on Rust cross-compilation. However many Rust packages in Gentoo generate the shell completions files by invoking the resulting binary, which will then output the shell completion (files). Unfortunately, this approach does not work when cross-compiling, since the resulting binary will be a binary of a different architecture than the build host.

See also https://www.mail-archive.com/gentoo-dev@lists.gentoo.org/msg99709.html

Describe the solution you'd like

The shell completion files should be an output of cargo build and not of the final binary.

Alternatives, if applicable

No response

Additional Context

No response

epage commented 3 months ago

Not to sure what is expected of clap. We document both workflows and a reason to generate completions as part of the program (rather than cargo build) is so that the completions can be generated on-demand, rather than statically, so that they "auto-update" with the program (for non-distro use cases). In fact, I'm going to be encouraging that workflow with the new completion system (#3166) as there is a tighter coupling between the completions and the users program.

Flowdalic commented 3 months ago

Not to sure what is expected of clap. We document both workflows

I wasn't aware that clap is already able to generate the completions as part of the build. Thanks for pointing this out!

In fact, I'm going to be encouraging that workflow

Feel free to encourage it. But with my package-maintainer hat on, there is no need for that if the application is installed via means of the Linux distribution. Because then, the completions are installed system wide via the package manager of the used Linux distribution and updated as soon as the package is updated. So, please keep the generate_to functionality, as it is relevant when packaging the application.