Skip to content
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

-Zrustdoc-scrape-examples not working if there is no workspace #13074

Closed
GuillaumeGomez opened this issue Nov 29, 2023 · 4 comments · Fixed by #13077
Closed

-Zrustdoc-scrape-examples not working if there is no workspace #13074

GuillaumeGomez opened this issue Nov 29, 2023 · 4 comments · Fixed by #13077
Labels
C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review Z-scrape-examples Nightly: rustdoc scrape examples

Comments

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Nov 29, 2023

Problem

In killercup/test-rustdoc-example-scraping-across-workspace-on-docrs#1 and in rust-lang/docs.rs#2305, we were able to find out that if you re-export non-workspace members, examples would not be scraped for them

Steps

$ git clone https://github.com/killercup/test-rustdoc-example-scraping-across-workspace-on-docrs.git
$ cargo +nightly doc -Zunstable-options -Zrustdoc-scrape-examples
$ ... open in browser and see no examples
$ git checkout HEAD~
$ cargo +nightly doc -Zunstable-options -Zrustdoc-scrape-examples
$ ... open in browser and see examples

Possible Solution(s)

When scraping examples from a package, cargo only asks for examples that use APIs from specific crates, presumably for performance reasons

        // Only scrape example for items from crates in the workspace, to reduce generated file size
        for pkg in cx.bcx.ws.members() {
            let names = pkg
                .targets()
                .iter()
                .map(|target| target.crate_name())
                .collect::<HashSet<_>>();
            for name in names {
                rustdoc.arg("--scrape-examples-target-crate").arg(name);
            }
        }

This is filtered to workspace members. Really what is needed is filtering for public dependencies which has recently been revived (rust-lang/rfcs#3516).

If the performance hit is not noticeable enough, we likely can remove this completely.

If the performance his is noticeable enough, the path forward:

  • Long term: switch this to filtering on public normal dependencies (recursively)
  • Short term: decide whether to
    • keep filtering by workspace members
    • take the perf hit and do no filtering
    • filter for all normal dependencies, recursively

Notes

No response

Version

No response

@GuillaumeGomez GuillaumeGomez added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Nov 29, 2023
@epage epage added Z-scrape-examples Nightly: rustdoc scrape examples S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Nov 29, 2023
@epage
Copy link
Contributor

epage commented Nov 29, 2023

@willcrichton Wanted to double check on your motivation for doing the workspace member filtering. Happen to remember if this was benchmarked?

@epage
Copy link
Contributor

epage commented Nov 29, 2023

If we filter by public dependency, because of the previous public dependency RFC, most of the infrastructure is in place. You'd just need to check if the unstable feature is active to make the behavior conditioned on the short term vs long term solution and then check the public dependencies in the long term solution.

The one piece of plumbing that might be missing is the taking the public dependency information at the package/dependency level and using it at the Unit level. I'm assuming its in place though.

Regardless of the short term solution, I'd recommend we include the long term solution of public dependencies because that is on a path for being stable for 2024 edition.

@willcrichton
Copy link
Contributor

I don't remember if I benchmarked it. To double-check, I did a quick experiment. I cloned Bevy and ran with latest Cargo:

cargo doc -Z unstable-options -Z rustdoc-scrape-examples
cat target/debug/deps/*.examples | wc -c

Then I modified the relevant for-loop to be:

for pkg in cx.bcx.packages.packages() {

And re-ran again. With workspace member filtering, the total size of the files was 643k. Without, the total size was 694k.

So from that one data point, there's no big space issue.

@GuillaumeGomez
Copy link
Member Author

Ok, sending the patch then. Thanks for taking a look @willcrichton !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review Z-scrape-examples Nightly: rustdoc scrape examples
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants