-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Tracking issue for -Zrustdoc-map #8296
Comments
There's another example at https://docs.rs/bevy_tiled_prototype/0.1.0/bevy_tiled_prototype/struct.TileMapChunk.html, which has broken links to I think this isn't a rustdoc bug because it has neither a documentation cache in |
Set docs.rs as the default extern-map for crates.io Helps address #8296, specifically the bit needed for rust-lang/docs.rs#1177. r? `@ehuss`
Rustdoc has response files since the latest nightly: rust-lang/rust#82261 |
See also rust-lang/rust#78909, which is waiting on review. |
I opened rust-lang/rust#82776 changing this; in practice, it should only hurt docs.rs (and I've asked the team to sign off before merging) and it gives crate authors more flexibility to point the links at their own site if they want to. |
…efault, but add a way to opt-in to the previous behavior ## What is an HTML root url? It tells rustdoc where it should link when documentation for a crate is not available locally; for example, when a crate is a dependency of a crate documented with `cargo doc --no-deps`. ## What is the difference between `html_root_url` and `--extern-html-root-url`? Both of these tell rustdoc what the HTML root should be set to. `doc(html_root_url)` is set by the crate author, while `--extern-html-root-url` is set by the person documenting the crate. These are often different. For example, docs.rs uses `--extern-html-root-url https://docs.rs/crate-name/version` to ensure all crates have documentation, even if `html_root_url` is not set. Conversely, crates such as Rocket set `doc(html_root_url = "https://api.rocket.rs")`, because they prefer users to view the documentation on their own site. Crates also set `html_root_url` to ensure they have documentation when building locally when offline. This is unfortunate to require, because it's more work from the library author. It also makes it impossible to distinguish between crates that want to be viewed on a different site (e.g. Rocket) and crates that just want documentation to be visible offline at all (e.g. Tokio). I have authored a separate change to the API guidelines to no longer recommend doing this: rust-lang/api-guidelines#230. ## Why change the default? In the past, docs.rs has been the main user of `--extern-html-root-url`. However, it's useful for other projects as well. In particular, Cargo wants to pass it by default when running `--no-deps` (rust-lang/cargo#8296). Unfortunately, for these other use cases, the priority order is inverted. They want to give *precedence* to the URL the crate picks, and only fall back to the `--extern-html-root` if no `html_root_url` is present. That allows passing `--extern-html-root` unconditionally, without having to parse the source code to see what attributes are present. For docs.rs, however, we still want to keep the old behavior, so that all links on docs.rs stay on the site.
…meGomez Give precedence to `html_root_url` over `--extern-html-root-url` by default, but add a way to opt-in to the previous behavior ## What is an HTML root url? It tells rustdoc where it should link when documentation for a crate is not available locally; for example, when a crate is a dependency of a crate documented with `cargo doc --no-deps`. ## What is the difference between `html_root_url` and `--extern-html-root-url`? Both of these tell rustdoc what the HTML root should be set to. `doc(html_root_url)` is set by the crate author, while `--extern-html-root-url` is set by the person documenting the crate. These are often different. For example, docs.rs uses `--extern-html-root-url https://docs.rs/crate-name/version` to ensure all crates have documentation, even if `html_root_url` is not set. Conversely, crates such as Rocket set `doc(html_root_url = "https://api.rocket.rs")`, because they prefer users to view the documentation on their own site. Crates also set `html_root_url` to ensure they have documentation when building locally when offline. This is unfortunate to require, because it's more work from the library author. It also makes it impossible to distinguish between crates that want to be viewed on a different site (e.g. Rocket) and crates that just want documentation to be visible offline at all (e.g. Tokio). I have authored a separate change to the API guidelines to no longer recommend doing this: rust-lang/api-guidelines#230. ## Why change the default? In the past, docs.rs has been the main user of `--extern-html-root-url`. However, it's useful for other projects as well. In particular, Cargo wants to pass it by default when running `--no-deps` (rust-lang/cargo#8296). Unfortunately, for these other use cases, the priority order is inverted. They want to give *precedence* to the URL the crate picks, and only fall back to the `--extern-html-root` if no `html_root_url` is present. That allows passing `--extern-html-root` unconditionally, without having to parse the source code to see what attributes are present. For docs.rs, however, we still want to keep the old behavior, so that all links on docs.rs stay on the site.
FWIW, rustdoc supports response files since 1.52: rust-lang/rust#82261 |
I don't think this is a rustdoc bug, see #8296 (comment). The way cargo manages this for normal dependencies is by passing |
|
Currently it's not recorded, but I think it's plausible to add :) cargo already sets it through CARGO_PKG_NAME so we just need to change rustc to add it to metadata. |
I'm interested in being able to build a fully offline documentation tree for rust development. Does this feature currently work? example: mkdir demo
cd demo
cat >rust-toolchain.toml <<EOF
[toolchain]
channel = "nightly-2024-11-25"
components = [ "rust-std", "rustc", "rust-docs" ]
targets = [ "x86_64-unknown-linux-gnu" ]
profile = "minimal"
EOF
cargo init --lib .
mkdir .cargo
cat >.cargo/config.toml <<EOF
[doc.extern-map]
std = "local"
EOF
cargo doc --no-deps -Zrustdoc-map -Zunstable-options this creates documentation for the default template library project, which as an example contains an running strace as: strace -ff -v -s 1024 cargo doc --no-deps -Zrustdoc-map -Zunstable-options 2>&1 | grep execve > doc.log confirms that has the implementation of this feature changed from what the docs currently state? am i just missing something? |
AFAIK this feature hasn't changed, but
|
Original issue: #6279Nightly: rustdoc-map
Implementation: #8287
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#rustdoc-map
Issues: Z-rustdoc-map
Summary
This feature adds the ability for Cargo to pass external documentation mappings to rustdoc, so that links to dependencies will use those external sites (like docs.rs). See the documentation for details on how to use it.
Unresolved issues
CARGO_CONFIG_DOC_EXTERN_MAP_REGISTRIES_CRATES_IO="…"
). This would be very difficult to support, because Cargo doesn't retain the registry name in SourceId. I looked into fixing that, but it is very difficult, and hard to make it reliable. I would lean towards not bothering with this (it has similar issues as thesource
table).cargo doc
. I can think of 3 options: all-deps, no-deps, direct-deps only. I think this would be useful, otherwise to use the rustdoc-map, one would always need to pass--no-deps
. This would probably also need a new command-line flag to override the config option (maybe a generalization of--no-deps
).crates-io = "https://docs.rs/"
. I think this should be relatively safe, since it only enhances the current behavior (people who use --no-deps will now have links instead of no links in their docs). DONE: Set docs.rs as the default extern-map for crates.io #8877cargo doc
. I would prefer to get more community feedback to see what makes sense. Two options:--no-deps
. This would engage rustdoc-map, but is a much more drastic change. The user would not have local indexing available.documentation
URL set inCargo.toml
is never consulted. I think this is unlikely to work with rustdoc, because it expects a certain structure to the API docs, and documentation URLs often point to user guides, or other things that aren't API docs. The#![doc(html_root_url = "...")]
attribute is overridden by the--extern-html-root-url
flag. This may be a good or bad thing depending on your perspective (should the user have control, or should the crate author?).Future extensions
These things can be done after stabilization, but should be considered to ensure this feature doesn't make them more difficult.
doc.extern-map.std = "include"
or something like that. (Or maybe just use build-std?) Support rustdoc root-url feature #6279 (comment)[doc]
table.--extern-html-root-url
flag will automatically handle second-level dependencies.cargo doc
only direct dependencies #2025 feature request: build docs for dependencies only #2801 Is there a way to run cargo doc and only get the documentation for direct dependencies of my project? #6421 https://crates.io/crates/cargo-makedocs--exclude winapi
?), and the rustdoc-map feature would automatically link those excluded crates' items to docs.rs. This could also be added to the[doc]
table. Allow skipping of specific dependencies in 'cargo doc' #4049The text was updated successfully, but these errors were encountered: