-
Notifications
You must be signed in to change notification settings - Fork 198
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
Document a binary? #238
Comments
I worked around this issue the same way the bitflags crate does: adding an example_generated.rs module that is only compiled when an
I'll leave this issue open for now even though my specific problem is solved, since it would still be useful to document whether |
@jyn514 Do we need to get an RFC for this to allow documentation for binary? |
@pickfire no, this does not need an RFC. To get this implemented, we need to
Possibly we could also make the behavior configurable, although I'd rather avoid that in a first draft of the feature. |
I'm happy to mentor or take PRs for this but I won't have time to work on it myself in the near future. |
Now I am wondering what to document in a binary. I think it is possible to put what needs to be documented in lib.rs. I kinda forgot my reason to work on this. But looking at the source section in docs.rs, I think it would be good if it shows the binary and examples probably? But IIRC cargo does not publish examples and binaries together. |
Unless you are filtering them out explicitly Cargo will include the example and binaries into the packaged crate. One issue with this is that the default binary and the library have the same target name, so you get a warning and lose the output from one if you build both:
I also think this could also need some work on the rustdoc side to make it first class:
(TBH I see much more usefulness out of being able to have documented examples than binaries, but they're very similar in implementation). |
@Nemo157 Ah, I didn't mean to document examples or binaries straight away, of course it might still be useful to document What I meant is the examples seemed to be missing from https://docs.rs/crate/clap/2.33.1/source/ |
That’s because exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"] |
Oh, sorry. I didn't notice that. |
Greetings! I just wanted to provide some additional context and a use-case for documenting binaries on doc.rs. I have created the cargo-wix Cargo subcommand. Generally, Cargo subcommands are hosted on crates.io and installed using Furthermore, the The discussion appeared to be focused on documenting examples, but there was this comment by @pickfire:
Just to give an example on documenting a binary versus a library, separate from package examples, I have structured the cargo-wix project as a binary (cargo-wix) that uses the library (wix) and provides both to developers that want to use the subcommand (binary) or interact with the WiX Toolset from another Rust project (library). With this organization, I have module-level documentation for the binary located in the Currently, only the library documentation is available on docs.rs. I have added a link to the binary documentation within the documentation, but it results in a "Crate not found" error through docs.rs. I believe this is because the link is automatically generated by rustdoc and since the binary documentation is not generated through docs.rs, the link is broken. Ideally, I would like both documentation available on docs.rs with the binary documentation being the default/primary as I believe this is the more useful and the current majority use-case of the project. The current workaround has been to host the documentation with GitHub pages and have the index.html file be for the binary module-level documentation. Please observe in the GitHub-hosted documentation, both the It is possible I am missing some configuration directive that would eliminate needing to use the GitHub Pages workaround and accomplish my ideal documentation state with no change to the excellent docs.rs codebase. A non-exhaustive review of issues on binary documentation yielded this issue, but I did not see any existing configuration directives that would be appropriate. Below is a snippet of the Cargo.toml file: [[bin]]
name = "cargo-wix"
[lib]
name = "wix" Any information and/or direction would be greatly appreciated. |
@volks73 you're not missing anything, this isn't implemented. It's waiting on the design issues mentioned in #238 (comment). |
I was thinking of adding the binary to the top-level project left section. Right now there is a big Like |
@pickfire that's a rustdoc section, you'd need to make rustdoc aware of the difference between binaries and libraries somehow. I think that's a good change, but it doesn't belong in docs.rs. |
But if it works in rustdoc why it shouldn't be in docs.rs? |
@pickfire it doesn't work in rustdoc, that's my point. I think it should be added to rustdoc instead of special cased by docs.rs. |
Ah, sorry. I was saying that if it works in the future. I was wondering why you say it shouldn't be in docs.rs even if it works in rustdoc. Time confusion. |
@pickfire if you have binaries and examples with I mentioned above that this gets a little confusing, and I think it would be a good rustdoc feature to be able to partition these based on the type of crate: So I think the required steps to get this working (and these can all be done independently) are:
|
The link looks good but the thing I was thinking before this was not to manually write out the docs, I was thinking of something like clap to auto-generate the docs to be displayed since clap have a bunch of metadata, especially with the release of clap 3 which it can now |
That's not really under the control of docs.rs, it seems likely to me that users could use a proc-macro to auto-generate their docs. e.g. for examples I tried out using this little snippet to embed the example source into the doc-page and it worked relatively well. #![feature(external_doc)]
//! ``rust
#![doc(include = "main.rs")]
//! `` By just getting the docs published on docs.rs then users can start experimenting with solutions like this (and maybe end up with new features for rustdoc, that don't need changes to docs.rs). |
Instead of This combined with 1 from @Nemo157's list would go a long way for me, but I am bias to my edge case. Fortunately for my use case I am able to have different Cargo target names for binary and library crates. I definitely see the value and problem with the naming conflicts between binary and library crates in a project. I think I actually used |
I think this would be fairly easy to do when there's only 1 binary and no library, and wouldn't require major changes to the UI or build logic. |
edit(@jyn514): Mentoring instructions for this issue are here: #238 (comment)
My crate has a macro that defines structs, and I want the docs to include an example of one of those generated structs. My solution was to write a binary,
src/bin/example.rs
, that invokes the macro.This works great when I run
cargo doc
. I seeexample
listed in the crates sidebar, and it contains docs for the generated struct. However, it doesn't show up in docs.rs.I tried adding this to
Cargo.toml
, but it didn't help:Is there some magical argument I can pass using
[package.metadata.docs.rs]
that will make it document the binary? Any other suggestions?The text was updated successfully, but these errors were encountered: