Skip to content

cargo doc should delete search-index.js before invoking rustdoc #15499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lolbinarycat opened this issue May 6, 2025 · 8 comments
Open

cargo doc should delete search-index.js before invoking rustdoc #15499

lolbinarycat opened this issue May 6, 2025 · 8 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-doc S-triage Status: This issue is waiting on initial triage.

Comments

@lolbinarycat
Copy link

Problem

Unlike the vast majority of build artifacts, search-index.js is both read and written by rustdoc, in order to append to it in a structured way.

This has the unfortunate side effect of persisting some state across cargo doc runs, as rustdoc will be able to see the output of the previous invocation.

This cannot be easily addressed within rustdoc, as it has no way to tell the difference between two invocations of rustdoc within one larger cargo doc invocation, and two different invocations of rustdoc across two different cargo doc invocations.

The weird read+write behavior of rustdoc is required because it does not have any equivalent to the "linking" step that rustc does, in which it can do one-time finalization and collection.

see rust-lang/rust#140698 and rust-lang/rust#133544 for some of the issues this causes

Proposed Solution

target/doc/search-index.js should be deleted by cargo doc before doing a full documentation rebuild (such as when the command-line arguments have changed, like in --document-private-items).

Notes

I believe crates.js also has a similar behavior.

@lolbinarycat lolbinarycat added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels May 6, 2025
@epage
Copy link
Contributor

epage commented May 6, 2025

Somewhat related: #8487

@epage
Copy link
Contributor

epage commented May 6, 2025

As cargo doc is intended to be additive across runs, I suspect we'd have a hard time deciding when the results should or shouldn't be additive.

@GuillaumeGomez
Copy link
Member

Agreed with @epage: if you remove the search index, you need to rebuild the doc of the current crate and of all its dependencies.

@lolbinarycat
Copy link
Author

@GuillaumeGomez but, if we're already going to do that, then perhaps cargo should delete things?

it feels quite difficult to fix these problems in rustdoc without support from cargo.

maybe we could add cargo doc --pure or something to ensure deterministic docs without getting rid of precompiled rlibs or the incremental build cache?

@GuillaumeGomez
Copy link
Member

I's not something we can fix in rustdoc. We could exit with a specific error or provide information in a specific way to cargo so it knows it needs to rebuild all docs.

@lolbinarycat
Copy link
Author

what about the case of duplicating crates in the search index? how can we fix that without breaking the case where there actually are multiple crates with the same name?

@GuillaumeGomez
Copy link
Member

Seems very unlikely to happen, no?

@lolbinarycat
Copy link
Author

which is unlikely, duplicating search index entries or a situation where multiple crates with the same name coexist in a dependancy tree?

the former is the cause of rust-lang/rust#133544, while the latter is easily caused by transitively depending on multiple semver-incompatible versions of the same crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-doc S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

3 participants