Skip to content

feat(docs): Render Cargo feature-gated code in docs#5967

Open
Mark-Simulacrum wants to merge 1 commit into
aws:mainfrom
Mark-Simulacrum:render-cfg-in-docs
Open

feat(docs): Render Cargo feature-gated code in docs#5967
Mark-Simulacrum wants to merge 1 commit into
aws:mainfrom
Mark-Simulacrum:render-cfg-in-docs

Conversation

@Mark-Simulacrum

Copy link
Copy Markdown
Contributor

Goal

This makes it much nicer to make use of gated functionality (whether unstable or not) because it's visible in the public documentation. It's still clearly marked as gated on the particular feature, so it shouldn't meaningfully increase the risk of usage of unstable surface area.

How

This uses a few features that are probably new to s2n team:

  • -Zcrate-attr allows injection of attributes at the crate root from the command line. We use it here to avoid touching the source code with cfg_attr -- but we could replace this with #![cfg_attr(docsrs, feature(doc_cfg))] for example. Happy to do that if we'd prefer the latter.
  • [package.metadata.docs.rs] encodes the configuration for docs.rs builds. package.metadata is a stable namespace for this kind of configuration.
  • auto_cfg/doc_cfg is a feature of rustdoc that is widely used (e.g., by tokio) to provide documentation while documenting what Cargo features or cfgs may be needed to enable it. See documentation here: https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#doccfg-and-docauto_cfg

Note that docs.rs always uses a (recent-ish) nightly toolchain to build documentation, so we're able to use unstable features there without significant issues. It is possible that these features will change in how to enable them but they've been fairly static for a long time and we would only see issues on a fresh publish (when docs are rebuilt), in the worst case publishing another release that disables this functionality.

Callouts

This enables all features rather than specifying a subset. It's possible we want to hide some of the more internal features (e.g., unstable-testing), but that would require listing out the features.

Testing

Built locally with cargo docs-rs, see sample output:

image image

Related

resolves #4641

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This makes it much nicer to make use of gated functionality (whether
unstable or not) because it's visible in the public documentation. It's
still clearly marked as gated on the particular feature, so it shouldn't
meaningfully increase the risk of usage of unstable surface area.
@Mark-Simulacrum Mark-Simulacrum marked this pull request as ready for review June 29, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render docs with features enabled

2 participants