Skip to content

feat: rebuild(-ish) rustdoc json for different version of same crates#16773

Open
motorailgun wants to merge 2 commits intorust-lang:masterfrom
motorailgun:rustdoc-rebuild
Open

feat: rebuild(-ish) rustdoc json for different version of same crates#16773
motorailgun wants to merge 2 commits intorust-lang:masterfrom
motorailgun:rustdoc-rebuild

Conversation

@motorailgun
Copy link
Copy Markdown
Contributor

@motorailgun motorailgun commented Mar 20, 2026

Fix #16291.

What does this PR try to resolve?

As discussed in the linked issue, cargo rustdoc --output-format=json doesn't rebuild for same crate name but with different versions. This is because current cargo implementation around rustdoc only specifies output paths/names by only its crate names, but not with version(hash) info.

This PR forces new layout for json output, and uplift the file into backward-compatible place.

How to test and review this PR?

  • JSON file's path could just be doc/<crate-name>-<hash>.json as this option is still unstable.
  • Uplifting will always happen even if uplifted json is fresh, and/or new layout is manually specified. (could not figure out how to prevent)

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-layout Area: target output directory layout, naming, and organization S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 20, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 20, 2026

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

@motorailgun motorailgun force-pushed the rustdoc-rebuild branch 2 times, most recently from a1ef71b to 04024f4 Compare March 21, 2026 02:47
let path = if bcx.build_config.intent.wants_doc_json_output() {
let hash = self.metadata(unit).unit_id();
let crate_name = unit.target.crate_name();
self.output_dir(unit)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't yet thought harder on this (and haven't yet started a thorough review), though I wonder if this can somehow leverage per-unit directory layout

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Zrustdoc-mergrable-info also puts things to new layout dir btw

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, will it be somewhere around <build_dir>/<profile>/build/<pkg_name>/<hash>/out/?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were the past relevant discussions

And if we want to put this under things like <build_dir>/<profile>/build/<pkg_name>/<hash>/out/ it might be better to move doc parts JSON into a sub-dir, and so does rustdoc output JSON, such as

  • <build_dir>/<profile>/build/<pkg_name>/<hash>/out/parts/ for doc-parts
  • <build_dir>/<profile>/build/<pkg_name>/<hash>/out/json/ for JSON output

I had a experimental commit here moving things weihanglo@f53fd1e.

If we ever did this, we might want to note this in the tracking rustdoc JSON output tracking issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @ranger-ross
what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all the feedback! As per reading about new layouts, I think (1) always put json into build/<pkg_name>/<hash>/out and (2) uplift if new layout is not specified - is a good option. For parts I am not sure, but if it's not something that changes by depend-ers, they could also just be at build/<pkg_name>/<hash>/out .

This comment was marked as outdated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think I was wrong. A unit that outputs JSON format won't be the same unit that output doc parts. I must have been brain dead.

No. No subdirectory needed unless one day JSON output also has doc parts JSON, which is unlikely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, then build/<pkg_name>/<hash>/out would be right for this PR I guess...?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@motorailgun
Copy link
Copy Markdown
Contributor Author

Updated to use new directory layout.

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

Labels

A-build-execution Area: anything dealing with executing the compiler A-layout Area: target output directory layout, naming, and organization S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo rustdoc --output-format=json sometimes doesn't rebuild for different versions of same crate name.

5 participants