Skip to content

Enable using build scripts to influence rustdoc #11784

Open
@decryphe

Description

@decryphe

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 what script_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 in cargo::core::compiler::rustdoc() or via cargo::core::compiler::build_context::BuildContext::rustdocflags_args. This would need parsing of the build script output, which seems to only be done in custom_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-docCommand-rustdocS-needs-team-inputStatus: Needs input from team on whether/how to proceed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions