Skip to content

Add an option to exclude source code from docs #75497

Description

@kpp

Describe the problem you are trying to solve

I ship a proprietary cdylib which I build from Rust code. I want to document the API using doc comments. However at the moment cargo doc puts the source code into target/doc/src/ which is not an option. I know I can rm target/doc/src/ however there is [src](goto source code) button left in the top right corner of the docs.

Describe the solution you'd like

cargo doc --exclude-source

Notes

Activity

  1. mexus commented on Aug 13, 2020

    @mexus

    At least some guidance on how-to-implement-that would be really appreciated!

  2. transferred this issue fromrust-lang/cargoon Aug 13, 2020
  3. ehuss commented on Aug 13, 2020

    @ehuss
    Contributor

    This is more of an issue for rustdoc, so moved to rust-lang/rust where its issue tracker resides.

  4. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    on Aug 13, 2020
  5. ollie27 commented on Aug 13, 2020

    @ollie27
    Contributor

    The #![doc(html_no_source)] crate level attribute prevents the source files from being emitted. Does that solve this issue?

  6. mexus commented on Aug 13, 2020

    @mexus

    OMG it does! Thanks a lot, @ollie27! Although why don't we make a rustdoc flag for that?

  7. GuillaumeGomez commented on Aug 14, 2020

    @GuillaumeGomez
    Member

    Well, let's add one then...

  8. jonas-schievink commented on Aug 14, 2020

    @jonas-schievink
    Contributor

    Does it make sense to have both an attribute and a command line flag for this? This doesn't seem like something you'd want to configure on a per-invocation basis, it's more like something that's permanent for a given code base (so the attributes fits better).

  9. Lonami commented on Aug 14, 2020

    @Lonami
    Contributor

    I think it fits the use case of being able to produce end-user documentation (without source links if providing binaries only) and internal documentation (with source links that may be helpful in some cases). I'm guessing it would also be more discoverable (rustdoc --help does not list attributes, but does list command-line flags).

  10. pickfire commented on Aug 14, 2020

    @pickfire
    Contributor

    Currently the only way to find this is through rustdoc book, which may not be quite discoverable if the users didn't saw that. I wish there is a manpage for rustdoc book but still currently man pages for rust is still not very good yet since we haven't figured out how to get to show the correct man pages for the current directory.

  11. mexus commented on Aug 14, 2020

    @mexus

    @jonas-schievink ,

    This doesn't seem like something you'd want to configure on a per-invocation basis, it's more like something that's permanent for a given code base (so the attributes fits better).

    Well, while the attribute is kinda sufficient, it would be also great to have an option to jump-to-source-code during the development phase. On the other hand, the attribute could be disabled/enabled with a feature flag, so having a rustdoc flag is not exactly required.

  12. jyn514 commented on Jul 2, 2021

    @jyn514
    Member

    #75522 was closed as won't fix since there are already ways to do this and it's not standard to duplicate attributes as arguments.

  13. kyrias commented on Jul 18, 2023

    @kyrias
    Contributor

    Is there currently any way to disable source generation for the current crate and all dependencies on stable? The suggestion from that PR requires an unstable flag that doesn't appear to have had any stabilization plans since it was added in #52355.

  14. jyn514 commented on Jul 18, 2023

    @jyn514
    Member

    no. i would like to stabilize that flag but i don't think it currently has a tracking issue. i am happy to mentor that work if you're interested in contributing :)

  15. GuillaumeGomez commented on Jul 18, 2023

    @GuillaumeGomez
    Member

    I think it deserves some more discussion: on docs.rs, users will still be able to browse the source code with docs.rs code viewer. But also, when building such crates locally, nothing prevent users to actually read the code they downloaded. So maybe a broader point of view should be taken here?

  16. kyrias commented on Jul 18, 2023

    @kyrias
    Contributor

    Personally the reason we had a need for this is because the docs for our project ended up getting big enough to reach a file size limit in our internal docs deployment, and so we wanted to be able to disable the source generation since we simply have no use for it and it ends up taking up a significant chunk of the output size.

    For now we're disabling building docs for dependencies instead, but it's rather unfortunate because having the docs for dependencies built with the correct features is very useful.

  17. GuillaumeGomez commented on Jul 18, 2023

    @GuillaumeGomez
    Member

    I'm surprised that the source code files make such a big difference. Shouldn't it represent a very small portion of the total?

  18. kyrias commented on Jul 18, 2023

    @kyrias
    Contributor

    In our case it represents just under 20% of the whole docs directory.

  19. GuillaumeGomez commented on Jul 18, 2023

    @GuillaumeGomez
    Member

    Wow, that's a lot. With this in mind, the option makes a lot more sense. Thanks for explaining. So for next steps, just as jyn514 explained. ;)

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

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.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