-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Figure out a way to link to downstream crates #74481
Comments
@Nemo157 also suggested that this be supported through cargo:
|
I don't think cargo would support something like that. That still introduces a cyclic dependency, even if it's technically feasible. Cargo doesn't really distinguish in the crate graph |
It would be good to clarify "upstream", my assumption would be that an "upstream crate" is a dependency, which should work with intradoc links? |
Oops, yeah I got upstream and downstream mixed up. |
@Manishearth cargo already allows "cyclic" dependencies for dev-dependencies, since they're not really cyclic in its build graph. Changing it to pass the current crate and dependents of it in as metadata when it calls |
@Nemo157 it's not trivial: dev-dependencies are dependencies of the test crates, which are independent crates. That's not the case for docs. even if we somehow solve this in cargo, the rustc infrastructure rustdoc relies on would not work. |
So another thought I had: Perhaps the solution for this is not in intra doc links. I'm not a fan of making intra doc links behave outside of the scope of paths and having forward decls: it's a major infrastructure change for rather minor benefit. The only main place that benefits is std which is designed as a facade crate. An alternate idea is to have a Thoughts? @rust-lang/rustdoc |
This does not solve the more general case of linking to downstream crates :/ I'm ok with working around this for std but I'd like to eventually have something that works for |
I kind of feel like there shouldn't be such a solution for other crates. Though I'd be open to eventually stabilizing DOC_ROOT |
I'm not much in favor for this and I really don't like the |
I don't actually remember what the usecase for this in |
@GuillaumeGomez I don't see how reexporting works? If libcore wants to link to std::String it can't, right now. DOC_ROOT is not an environment variable, it's just a signal to rustdoc to replace it. |
@Nemo157 oh, hmm, that's a fair point. |
Ah I see, for me it's upstream looking "up" this way. This explains my confusion. I still don't think this is a good idea, a crate shouldn't know about its users. And there is also the issue @Nemo157 brought up too. :) |
One possibility is to resolve links on the extra docs on the re-export relative to the current crate. So /// Link to [`crate::string::String`]
pub use core::str::str; Would work correctly from std and the docs just wouldn't be present in libcore. That's really annoying for the end user though and also requires we fix the bug that it's currently resolved relative to the original crate. |
@GuillaumeGomez Yeah, I agree. I would rather we didn't support this. This ties in a bit to a wishlist item i've had for ages where Rust understands the concept of a "package": multiple rust crates that are friends and released together. Like all the futures-foo crates, or the regex-foo crates. They'd have special dispensation when it comes to breaking coherence rules, but you'd still be able to pull in a fraction of a package if you wish. These could be documented together and would also fix the docs.rs problem. However, that's waaay out of scope for this. I still think using |
An idea @Mark-Simulacrum came up with is to have 'unchecked' intra-doc links: link to a fully-specified type like One possible issue here is how to determine the doc root for the crate - docs.rs uses |
I guess since docs.rs allows custom flags crate authors could add |
I think to start we could aim to support local usage, and optimistically match the layout generated by Cargo's normal invocation in the same working directory of rustdoc. Supporting docs.rs I would do via doc-dependencies (in a metadata section, like docs.rs already does), so something like: [package.metadata.docs-rs]
links-to = ["futures:0.3", "tokio:0.2"] That can then generate something like I would personally still feel like we could formalize this idea of doc-dependencies and have Cargo (or whoever) generate similar html-roots for rustdoc. |
I think the problem with doc-dependencies is that making that kind of thing work really requires completely changing the model of how rustdoc builds things, and it's really not worth it to do that just to get facade intra-doc-links working, |
I feel like that's only true if these links are to be checked? That was my impression of our discussion yesterday - that we could indeed generate links if given a fully qualified path and namespace. Larger projects like rust-lang/rust already run linkcheck and similar, so there we would get most of the benefits already. |
There are many links that I could not fix in the luent crate, but they are not a problem in the luent-bundle crate. I do not understand why these problems arise. Relevant readings on Rust docs: - Last addition to rustdoc capacities: https://rust-lang.github.io/rfcs/1946-intra-rustdoc-links.html - Frontend/backend crates pattern: https://users.rust-lang.org/t/cross-crate-documentation-links-in-a-workspace/67588 - Help linking to an external crate (for which we want to link only on the documentation level): rust-lang/api-guidelines#186 - Open issue on how to do that: rust-lang/rust#74481
There are many links that I could not fix in the luent crate, but they are not a problem in the luent-bundle crate. I do not understand why these problems arise. Relevant readings on Rust docs: - Last addition to rustdoc capacities: https://rust-lang.github.io/rfcs/1946-intra-rustdoc-links.html - Frontend/backend crates pattern: https://users.rust-lang.org/t/cross-crate-documentation-links-in-a-workspace/67588 - Help linking to an external crate (for which we want to link only on the documentation level): rust-lang/api-guidelines#186 - Open issue on how to do that: rust-lang/rust#74481
Previously, `BTreeMap` tried to link to `crate::collections`, intending for the link to go to `std/collections/index.html`. But `BTreeMap` is defined in `alloc`, so after the fix in the previous commit, the links instead went to `alloc/collections/index.html`, which has almost no information. This changes it to link to `index.html`, which only works when viewing from `std::collections::BTreeMap`, the most common place to visit the docs. Fixing it to work from anywhere would require the docs for `std::collections` to be duplicated in `alloc::collections`, which in turn would require HashMap to be `alloc` for intra-doc links to work (rust-lang/rust#74481).
# Objective This PR continues #8885 It aims to improve the `Mesh` documentation in the following ways: - Put everything at the "top level" instead of the "impl". - Explain better what is a Mesh, how it can be created, and that it can be edited. - Explain it can be used with a `Material`, and mention `StandardMaterial`, `PbrBundle`, `ColorMaterial`, and `ColorMesh2dBundle` since those cover most cases - Mention the glTF/Bevy vocabulary discrepancy for "Mesh" - Add an image for the example - Various nitpicky modifications ## Note - The image I added is 90.3ko which I think is small enough? - Since rustdoc doesn't allow cross-reference not in dependencies of a subcrate [yet](rust-lang/rust#74481), I have a lot of backtick references that are not links :( - Since rustdoc doesn't allow linking to code in the crate (?) I put link to github directly. - Since rustdoc doesn't allow embed images in doc [yet](rust-lang/rust#32104), maybe [soon](rust-lang/rfcs#3397), I had to put only a link to the image. I don't think it's worth adding [embed_doc_image](https://docs.rs/embed-doc-image/latest/embed_doc_image/) as a dependency for this.
# Objective This PR continues #8885 It aims to improve the `Mesh` documentation in the following ways: - Put everything at the "top level" instead of the "impl". - Explain better what is a Mesh, how it can be created, and that it can be edited. - Explain it can be used with a `Material`, and mention `StandardMaterial`, `PbrBundle`, `ColorMaterial`, and `ColorMesh2dBundle` since those cover most cases - Mention the glTF/Bevy vocabulary discrepancy for "Mesh" - Add an image for the example - Various nitpicky modifications ## Note - The image I added is 90.3ko which I think is small enough? - Since rustdoc doesn't allow cross-reference not in dependencies of a subcrate [yet](rust-lang/rust#74481), I have a lot of backtick references that are not links :( - Since rustdoc doesn't allow linking to code in the crate (?) I put link to github directly. - Since rustdoc doesn't allow embed images in doc [yet](rust-lang/rust#32104), maybe [soon](rust-lang/rfcs#3397), I had to put only a link to the image. I don't think it's worth adding [embed_doc_image](https://docs.rs/embed-doc-image/latest/embed_doc_image/) as a dependency for this.
I do think the real solution to problems like this is to allow resolving links within Consider this issue from If you try to build something like this with [dev-dependencies]
docify = "0.2" //! ### Interned Example
#![cfg_attr(doc, doc = docify::embed_run!("tests/tests.rs", test_interned_showcase))]
If we've decided adding (originally mentioned in rust-lang/cargo#8905 (comment)) |
I think that's got the same architectural challenges as doc-dependencies, really, because doc targets currently work by building the crate itself and then producing a different artifact, unlike dev targets which are effectively new crates that depend on the main crate (and thus can depend on things that depend on the crate itself). The path to fixing this would be to explicitly make rustdoc consume crate metadata of an already compiled crate rather than intercepting compilation. This ought to be doable; and might even just be good practice, but I suspect it'll be quite hard. If we're going to making this architectural change anyway I'd prefer to do it with some separation (it's already frustrating that you can't do dev-dependencies at a per target level).
I think this is a pretty subjective judgement, it definitely is not intended to work that way |
That's fair. The lore I had encountered when asking around the community is "cargo doc is supposed to be under the auspices of I would push back a bit by saying it is wild that we have An alternative solution would be greater flexibility in |
Yeah, the actual thing is that doc tests are under the auspices of
Yes, but either way that would not let you do cyclic dependencies.
More complex and a violation of separation of responsibilities because a lot of And also it would not solve this problem. I would in general not be too excited about solutions that don't solve the particular problem of linking downstream because in my experience that is the number one reason people typically need doc dependencies. |
I definitely agree and I would add it's not always downstream, there is very often the desire to link to items in associated crates like crates often used with your crate that you have no dependency relationship with (in either direction). Right now talking about items like these is basically discouraged because there is no easy way to link to them without them being a direct dependency. Ideally we should be able to link to any item in any crate without affecting the dependency tree other than when docs are compiling. Annoyingly, we can use items from "associated" crates in doc tests via |
Yes, but I highlight downstream because it's a crucial component, and I think work in this feature space in a way that does not support that will eventually lead to two ways of doing things, so in general I would like to focus on solutions that do allow for downstream stuff; which does seem to be the majority use case and also the hardest one. |
FTR one doesn't have to switch all of rustdoc to such a scheme, it's enough to add either an entirely new driver, or something that uses the rustdoc or rustc drivers to, for a given input path and metadata file, resolve that path, and outputs a relative html url (or a json diagnostic if the resolution failed). As in, one doesn't have to touch the main rustdoc path that generate the html. That path would shell out to such a command. It would be a flag like IMO a "link to downstream/external" feature should only be weakly coupled into the existing resolution and metadata system, precisely for the architectural concerns. No changes to the fundamental nature of rustdoc would be needed for the normal non-resolution mode of rustdoc. Of course, this still requires implementing a mode that reads the metadata of the specific crate. One would also need cargo integration of Usually there aren't that many links to downstream crates, but if you want to make it faster, you could pass multiple paths you are interested in e.g. via json. Similar things are already done with the doctests where rustdoc create a fully fledged compiler environment, it instead spawns the rustc process. Here too, a .rs file is created on disk because passing all of the test on the command line isn't really great :). Regarding the points on the mental model, I think the point of view that is the most important for documentation is that of the readers. Readers generally have the entire problem domain in mind, including downstream or unrelated crates. E.g. when I read the |
Yep, such a design might work! It's still a fair amount of work to get all that working, though. Honestly, I feel that making the model more like test targets where there's a separate target that is allowed to depend on anything is probably better in the long run over doing this kind of frankenbuild. But it depends. |
I think this matches a lot of people's mental models for how they think it already works anyway |
Just going to add my comment from #121436 (which I filed without noticing this issue): I do agree that the test target being its own thing is a good argument for supporting this, but I think it's also worth reiterating that doc tests also fall into this category, and those themselves are managed by rustdoc. So, it feels appropriate that rustdoc would leverage something similar to what it does for doctests when doing intra-doc links, being able to access Additionally, at least in libstd, it manages to have access to the normal std prelude in doctests, seemingly as some kind of weird hack. I assume that some kind of hack could be done to make linking std items work, but I also know nothing and am essentially just guessing. |
Doctests simply shell out to a new rustc instance (basically rustdoc dumps the doctest code into a file after adding But yeah not being a able to link to std items from core is repeatedly a pain and sometimes leads to us writing worse docs since we can't add the links we need to add. |
# Objective This PR continues bevyengine/bevy#8885 It aims to improve the `Mesh` documentation in the following ways: - Put everything at the "top level" instead of the "impl". - Explain better what is a Mesh, how it can be created, and that it can be edited. - Explain it can be used with a `Material`, and mention `StandardMaterial`, `PbrBundle`, `ColorMaterial`, and `ColorMesh2dBundle` since those cover most cases - Mention the glTF/Bevy vocabulary discrepancy for "Mesh" - Add an image for the example - Various nitpicky modifications ## Note - The image I added is 90.3ko which I think is small enough? - Since rustdoc doesn't allow cross-reference not in dependencies of a subcrate [yet](rust-lang/rust#74481), I have a lot of backtick references that are not links :( - Since rustdoc doesn't allow linking to code in the crate (?) I put link to github directly. - Since rustdoc doesn't allow embed images in doc [yet](rust-lang/rust#32104), maybe [soon](rust-lang/rfcs#3397), I had to put only a link to the image. I don't think it's worth adding [embed_doc_image](https://docs.rs/embed-doc-image/latest/embed_doc_image/) as a dependency for this.
After #73101 there is no way to link to items in downstream crates. This is fairly common to try;
futures
does this extensively (#64193), as doescore
/std
(#73423).On one hand, this clearly breaks rust's scoping rules: inner crates can't refer to the types of their dependencies because it causes a cyclic dependency. So there's an argument to be made for saying this is just not supported.
On the other hand, this seems really useful. In fact it used to work for re-exports from the inner to outer crate, but only when you documented both crates at the same time, and the outer crate after the inner crate (this was #73699). So it would be great to find a way to make it work.
cc @Manishearth, @Nemo157
The text was updated successfully, but these errors were encountered: