Skip to content

rustdoc’s approach to producing output needs to be rethought #14595

Closed
@chris-morgan

Description

@chris-morgan

rustdoc was built under a single-crate-universe assumption: that the documentation would be just for that crate. While that assumption held, Rust-to-HTML generation worked fine.

This assumption is now broken. We have the implementors/**/*.js technique for trait implementatons; search pulls its information for many crates from one; the order in which you build the documentation of crates matters and—for the Rust repository—make docs produces different output to make -j docs.

It is precept upon precept,
precept upon precept;
line upon line,
line upon line;
here a little,
there a little.

It’s time to stop writing new workarounds and address the basic problem that we have here: rustdoc needs to handle this multiple-crates world intelligently. This means ditching the simple and, alas, simplistic single-pass Rust-to-HTML approach.

I propose in its stead this model:

  • First pass, done per crate: extract all the metadata and write it in serialized form, not HTML/JavaScript/whatever. I don’t care what format.
  • Second pass, which need only be done after all crates but can be done more frequently without harm: using the metadata, write all the HTML and whatever JavaScript is still necessary (this way, I think it will be for the search only, not the crate-level sidebar and trait implementations stuff).

By default, the second pass should probably still be run, but it can be turned off with a flag like --no-html for efficiency when you do have multiple crates. Or you can run the HTML pass by itself, which will allow meaningful Makefile dependencies in this blasé-with-respect-to-detail example, allowing efficient, consistent and correct make -j behaviour:

doc/index.html: doc/a.json doc/b.json doc/c.json
    rustdoc --html doc/{a,b,c}.json

doc/%.json: src/%/lib.rs
    rustdoc --no-html src/%/lib.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions