Skip to content

Host --output-format json files in addition to generated HTML #1285

Closed

Description

@deeprobin

I need this to implement my own "doc"-frontend for me into a multi-page-application.

Activity

  1. syphar commented on Feb 26, 2021

    @syphar
    Member

    @deeprobin what kind of information would you need?

    docs.rs is just hosting some metadata and is serving the HTML files generated by rustdoc,

  2. deeprobin commented on Feb 26, 2021

    @deeprobin
    Author

    Oh okay. Then it would be better if I open a issue in the rustdoc repository? I thought this was the right repository for this.

  3. Nemo157 commented on Feb 26, 2021

    @Nemo157
    Contributor

    Rustdoc has an in-progress JSON backend: rust-lang/rust#76578

    There has been some very brief discussion of docs.rs generating and hosting these files along with the html. But at the moment I think it's quite buggy (e.g. rust-lang/rust#80664 is probably going to fail a large proportion of builds) and the format is unstable. I think it would make sense to wait a little longer till it has stabilized a bit more before we add it here (I know of at least a couple of users that are already building alternative renderers based on the json, which will hopefully drive it towards stabilization).

  4. changed the title [-]Can docs.rs generate .json files?[/-] [+]Host `--output-format json` files in addition to generated HTML[/+] on Feb 26, 2021
  5. added
    A-buildsArea: Building the documentation for a crate
    C-enhancementCategory: This is a new feature
    S-blockedStatus: marked as blocked ❌ on something else such as an RFC or other implementation work.
    on Feb 26, 2021
  6. DottieDot commented on Jul 2, 2022

    @DottieDot

    Any progress/updates on this?

  7. syphar commented on Jul 3, 2022

    @syphar
    Member

    There are still open ICEs when generating the JSON (see this current discussion on zulip, rust-lang/rust#93518 is one of the fixes.

    When this is solved I believe we have to partially finish #795 so we have the additional spare capacity for running the additional builds.

    Of course on top of that the actual code change needs to be done.

  8. jyn514 commented on Jul 3, 2022

    @jyn514
    Member

    I don't think we should start hosting this until the JSON backend is stabilized. The output format is likely to change several more times before stabilization.

  9. syphar commented on Jul 3, 2022

    @syphar
    Member

    yeah, also valid point, I only had in mind that we could find more ICEs when running it for docs, but the format changing could be annoying for users of the JSON

  10. syphar commented on May 14, 2025

    @syphar
    Member
    • we're planning on building the JSON with the same docs.rs metadata (= the same feature set) as the HTML docs. ( this seems to be OK for cargo-semver-checks too @obi1kenobi )
    • the download will be a single JSON download via CDN, probably gz-compressed.

    there are some missing features before we deem the format stable enough: ( coming from @jyn514 )

  11. syphar commented on May 17, 2025

    @syphar
    Member

    next set of notes coming from the all-hands / rustweek: we can actually start building & hosting rustdoc json.

    about the implementation:

    • memory usage of the JSON build is higher than the HTML build. We might hit limits for crates that reach that limit.
    • Files would be compressed on S3, potentially with zstd
    • download API is a redirect to static.docs.rs for download, similar to the archive download.
    • format_version could be part of the filename / API.
    • question: can we keep hosting old format versions? and provide via API?

    Normal rebuilds for the latest version of each crate would then also build & upload the rustdoc json. So after a couple of months of this being live, all latest versions have rustdoc json.

    There are some pending additions that will come later that will make it easier to link between json docs easier (notably: extend the information we provide in external_crates)

    edit: don't forget, we have a separate JSON output per target to store.

  12. removed
    S-blockedStatus: marked as blocked ❌ on something else such as an RFC or other implementation work.
    on May 17, 2025
  13. syphar commented on May 17, 2025

    @syphar
    Member

    implementation notes from first codebase read:

    • rustdoc will clear the /target/doc/ directory before the HTML or JSON builds. So we have to pull out the JSON output before we run the HTML build
    • we have to store & support multiple targets.
    • due to the potentially higher memory usage of rustdoc json, the JSON build might fail when HTML doesn't. We want HTML to be published even after a failed JSON build. Do we need to store separate logs for crate authors to see this somewhere? Or is our internal sentry / log good enough, similar to coverage-generate?
    • any API would probably redirect to default target if no target is given.

    structure on S3 bucket is currently:

    • rustdoc: /rustdoc/{krate}/{version}.zip
    • sources: /sources/{krate}/{version}.zip
    • build logs: /build-logs/{build_id}/{target}.txt

    and legacy locations before archive-storage

    • rustdoc: /rustdoc/{krate}/{version}/
    • sources: /sources/{krate}/{version}/

    after each build we store the archive, and run delete_prefix on the legacy locations.

    For rustdoc JSON we preferably want a folder structure where we can later s3 ls and return the available format-versions?

    This means the best structure is probably a separate root: /rustdoc-json/{krate}/{version}/{target}/{format_version}.json.zst, perhaps duplicating krate & version & target on the filename for a nicer download. s3 ls could use all files from the target folder.

    That also means every request to docs.rs for a rustdoc JSON file needs an s3 ls call. The only way to prevent that, so we can statically determine the path, would be if we remove the format version from the path, or additionally maintain a file without the format version that we overwrite each rebuild.

  14. syphar commented on May 17, 2025

    @syphar
    Member

    @obi1kenobi following up on your request to be able to fetch old format versions, if we have them.

    With my approach from above you would be able to run parallel requests to:

    https://static.docs.rs/rustdoc-json/{krate}/{version}/{target}/{format_version}.json.zst

    using your list of supported format versions. You'll get either the file or a 404 then, the 404s also cached when I updated the cloudfront config.

    Would that suffice for your use-case?

    ( perhaps I add the other parameters to the filename additionally to make it self consistent in your download directory)

  15. obi1kenobi commented on May 20, 2025

    @obi1kenobi
    Member

    Broadly this all sounds good! Thanks for looking into it and writing it up, I really appreciate it.

    If it avoids the s3 ls call, I'd be fine with also having an option to download the "latest" format version available using a non-format-versioned request path. This would likely be useful to cargo-semver-checks too: for example, say we're running a SemVer breakage study of crates.io crates. For each release, we'd look to download the latest rustdoc JSON format version available, together with the same format version for the immediately prior release. So long as both files are the same JSON format version, and the format is reasonably new (so cargo-semver-checks still supports it), everything would work well.

    I like the idea of adding the parameters to the filename, for when I inevitably need to download a bunch of these files manually to triage some bug in cargo-semver-checks.

    So maybe the paths could normally be something like https://static.docs.rs/rustdoc-json/{krate}/{version}/{target}/{krate}_{version}_v{format_version}.json.zst, and the latest one (if you choose to go for it) could be a redirect from https://static.docs.rs/rustdoc-json/{krate}/{version}/{target}/{krate}_{version}_latest.json.zst to whichever version is latest?

    Or if the krate component already uses underscores, then use dashes to disambiguate instead?

    All this is super minor though — I think everything you proposed is good and the rest is just some tiny tweaks. Thanks again!

  16. jyn514 commented on May 21, 2025

    @jyn514
    Member

    If it avoids the s3 ls call, I'd be fine with also having an option to download the "latest" format version available using a non-format-versioned request path.

    the latest one (if you choose to go for it) could be a redirect from https://static.docs.rs/rustdoc-json/{krate}/{version}/{target}/{krate}_{version}_latest.json.zst to whichever version is latest?

    note that static.docs.rs is not running any kind of dynamic code (it's basically just a read-only view of docs.rs' s3 bucket). we strongly discourage people from ever using static.docs.rs. instead they should use the download urls we document at https://docs.rs/about/download. so the redirect would be something like https://docs.rs/crate/{krate}/latest/json-docs.

    the thing we are discussing here is not the public api, it's the implementation, because the layout of the S3 bucket affects how quickly we can do operations on it.

  17. obi1kenobi commented on May 21, 2025

    @obi1kenobi
    Member

    Ah TIL, thanks!

    Yes, so long as it's reasonable to download a specific rustdoc JSON format version for a given crate & release, I'm fine with anything.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-buildsArea: Building the documentation for a crateC-enhancementCategory: This is a new feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions