Skip to content

Rustdoc merging with RFC3662#1297

Open
cormacrelf wants to merge 8 commits into
facebook:mainfrom
cormacrelf:rustdoc-rfc3662
Open

Rustdoc merging with RFC3662#1297
cormacrelf wants to merge 8 commits into
facebook:mainfrom
cormacrelf:rustdoc-rfc3662

Conversation

@cormacrelf
Copy link
Copy Markdown
Contributor

@cormacrelf cormacrelf commented Apr 17, 2026

Fixes #1097. Basically you can now:

  • Generate merged rustdoc for all your first-party crates, or any subset of them, via bxl
  • With a search index of all of them
  • With all srcs and cross-crate trait impls available
  • With perfect caching of the single-crate doc builds
  • With the option to link to docs.rs for 3rd party crates
  • With all rustdoc_flags respected
  • With forwards compat for the very recent change from rustdoc --emit=invocation-specific to --emit=html-non-static-files

Also deals somewhat with the problems in #876 by making -Zcrate-attr easier to use with a simple attr on rust_library(rustdoc_html_root_url= ...). If this is merged, we should update reindeer to generate this automatically.

Also makes rustdoc themes easier to use, by generating stub theme files so we don't force a rebuild of all crate docs when making tiny tweaks to themes. The only thing rustdoc actually looks at until the final merge step is the filename. This applies to regular [doc] subtargets, but they get the real theme files.

All this is exercised in the example project.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 17, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 17, 2026

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D101353961. (Because this pull request was imported automatically, there will not be any future comments.)

Implements RFC 3662 mergeable rustdoc in the rust prelude with a BXL that merges per-crate docs into one HTML tree. The reusable rustdoc_merge helper lives in doc_merge.bzl so downstream BXL can bring its own target discovery and filtering.

Uses --emit=html-non-static-files.
This avoids writing shared js/css assets in every crate build. Since the flag
has recently been renamed, we have a compat layer for the old flag names.
This all means we don't have to touch this for another year hopefully.
And now that we know which ones are externed, we exclude them from the bxl target sets.
Rustdoc themes have to be provided when generating HTML for all crates.
That means the naive way of adding themes results in full crate graph
rebuilds every time you tweak the theme. This way is nicer.
We were getting a random crate in merge_output/src, as src itself
was present in all crates' html outputs. We need to do a recursive
directory merge, basically.
This handles hidden args better
@cormacrelf
Copy link
Copy Markdown
Contributor Author

cormacrelf commented Apr 22, 2026

Maybe @dtolnay would like to review?

There are some comments about how rustdoc resolves external links to docs.rs for third party crates, to the effect of "rustdoc is pretty annoying here" that might be appropriate to PR against rustdoc itself. If its priority order for getting a URL while documenting a downstream crate were not so weird, we could use the --extern-html-root-url override (or however you spell it) and not have to use -Zcrate-attr=doc(...).

The hacky way of adding -Zcrate-attr works pretty well for now and does deal with incorrect-but-baked-into-source doc(html_root_url) metadata that appears on a fair few third party crates. I understand meta just uses a macro for such purposes but making an attribute on rust_library overall makes this feature way easier to use and allows us to exclude third party crates from doc builds at all in the BXL. If we fixed rustdoc and used flags on downstream deps instead, we would still need the upstream crate to know its URL to put it in a provider. And finally, if we get reindeer generating docs.rs urls from the version info, it will work out of the box.

Maybe the BXL could also do with some work, you are better at BXL than I am.

Only other thing I can think to add is a wrapper script for the BXL that hosts it on localhost or opens an appropriate index.html in the browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rustdoc builds should be mergeable using RFC3662

1 participant