Cargo exports an “OUT_DIR” environment variable to build scripts so that build scripts can store outputs there. And for generated source code this is fine. However when generating final artifacts that should be distributed with the binary, such as documentation (man pages) or shell completion scripts, storing them in the OUT_DIR is somewhat problematic. Not only is OUT_DIR different per package, but the path has some kind of hash in it, and isn’t included in the output of
cargo metadata. Which makes such artifacts difficult to discover with tools like
cargo-deb or to write robust packaging scripts.
As a specific example, ripgrep uses clap to generate shell completion scripts, which it stores in the OUT_DIR, and the maintainer uses
cargo-deb to produce debian packages. However, the resulting debs don’t contain the completion scripts.
cargo-deb has a way to specify additional assets by path to include, but since the OUT_DIR isn’t fixed, it isn’t possible to specify a fixed path for the completion scripts.
I’m not sure what the solution is, but I think there should be a better way to generate final artifacts in a way that makes it easy to package them with the binary.