Description
Problem
Cargo currently can not pass any of information generated by a build script to rustdoc
.
Specifically, we have a use-case where we would like the version string generated using git describe --dirty
for an application to be propagated into both the binary (it logs the version upon startup - which is made possible using a Rust build script) and the documentation (currently impossible).
Proposed Solution
With my limited knowledge of cargo, it seems that cargo::core::compiler::rustdoc()
should be adjusted to either:
- Read
script_metadata
before setting the--crate-version
arg. Not sure whatscript_metadata
contains though, so this may not actually lead to the desired functionality. - Implement a
rustdoc-env
or similar new key that can be output from a build script and will be processed incargo::core::compiler::rustdoc()
or viacargo::core::compiler::build_context::BuildContext::rustdocflags_args
. This would need parsing of the build script output, which seems to only be done incustom_build
.
Notes
If someone with better knowledge of Cargo could propose a viable solution to this request, I'm more than happy to do the implementation work myself and prepare a PR, either for a generic way to feed env vars to rustdoc
or for handling a dynamic source for crate versions.
I'm using this solution as described in #6583 for the binary, and would like to extend that to the docs.