rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.88k stars 12.67k forks source link

--extern-html-root-url uses library names to identify dependencies, failing to handle multiple versions #76296

Open Nemo157 opened 4 years ago

Nemo157 commented 4 years ago

With this package that uses dependency renaming:

# Cargo.toml

[package]
name = "foobar"
version = "0.1.0"
edition = "2018"

[dependencies]
ac = { package = "async-compression", features = ["stream", "gzip"], version = "0.3" }
ac02 = { package = "async-compression", features = ["stream", "gzip"], version = "0.2" }
// src/main.rs

#[doc(inline)]
pub use {ac::stream::GzipDecoder, ac02::stream::GzipDecoder as GzipDecoder02};
#[doc(no_inline)]
pub use {ac::stream::GzipEncoder, ac02::stream::GzipEncoder as GzipEncoder02};

I tried to build documentation that can link to both of the upstream docs.rs documentation pages:

cargo rustdoc --locked -- -Z unstable-options
--extern-html-root-url ac02=https://docs.rs/async-compression/0.2.0
--extern-html-root-url ac=https://docs.rs/async-compression/0.3.5
rustdoc
--edition=2018
--crate-type lib
--crate-name foobar src/lib.rs
-o /tmp/tmp.ni0GV7DIZf/foobar/target/doc
--error-format=json --json=diagnostic-rendered-ansi
-Z unstable-options
--extern-html-root-url 'ac02=https://docs.rs/async-compression/0.2.0'
--extern-html-root-url 'ac=https://docs.rs/async-compression/0.3.5'
-L dependency=/tmp/tmp.ni0GV7DIZf/async-compression/target/debug/deps
--extern ac02=/tmp/tmp.ni0GV7DIZf/foobar/target/debug/deps/libasync_compression-ad6b882a4c15a1f0.rmeta
--extern ac=/tmp/tmp.ni0GV7DIZf/foobar/target/debug/deps/libasync_compression-875810b2ce8d0002.rmeta
--crate-version 0.1.0

This failed to link to either of the non-inlined exports because it seems that --extern-html-root-url expects the library name instead, changing to use that:

cargo rustdoc --locked -- -Z unstable-options
--extern-html-root-url async_compression=https://docs.rs/async-compression/0.2.0
--extern-html-root-url async_compression=https://docs.rs/async-compression/0.3.5
rustdoc
--edition=2018
--crate-type lib
--crate-name foobar src/lib.rs
-o /tmp/tmp.ni0GV7DIZf/foobar/target/doc
--error-format=json --json=diagnostic-rendered-ansi
-Z unstable-options
--extern-html-root-url 'async_compression=https://docs.rs/async-compression/0.2.0'
--extern-html-root-url 'async_compression=https://docs.rs/async-compression/0.3.5'
-L dependency=/tmp/tmp.ni0GV7DIZf/async-compression/target/debug/deps
--extern ac02=/tmp/tmp.ni0GV7DIZf/foobar/target/debug/deps/libasync_compression-ad6b882a4c15a1f0.rmeta
--extern ac=/tmp/tmp.ni0GV7DIZf/foobar/target/debug/deps/libasync_compression-875810b2ce8d0002.rmeta
--crate-version 0.1.0

This successfully added links on both, but both directing to version 0.3.5 since that was the last flag specified.

(I'm not sure of the correct solution for this, currently docs.rs only passes --extern-html-root-url for direct dependencies, so changing to use the same name as used for --extern would work for that; but it seems to me that docs.rs should be passing a flag for all dependencies, since it's possible for documentation from a dependency of a dependency to bubble-up and be rendered, so it should be possible to set the html-root-url for them all, I'm not sure how we would identify the crates in that case).

Meta

rustdoc 1.47.0-nightly (7e6d6e5f5 2020-08-16)
Nemo157 commented 4 years ago

An idea for supporting all dependencies, we could run a first cargo check --message-format=json and extract all the .rmeta filenames for all crates built, then pass flags using those as the key instead

--extern-html-root-url libasync_compression-ad6b882a4c15a1f0.rmeta=https://docs.rs/async-compression/0.2.0
--extern-html-root-url libasync_compression-875810b2ce8d0002.rmeta=https://docs.rs/async-compression/0.3.5
jyn514 commented 3 years ago

This is basically the same as https://github.com/rust-lang/rust/issues/56169, but I'll leave it open to make sure that someone remembers to update extern-html-root-url whenever the other issue gets fixed.

Nemo157 commented 3 years ago

Got a failing testcase at least: https://github.com/rust-lang/rust/compare/master...Nemo157:issue-76296.

I don't think this is really related to #56169 since this issue should be fixable without fixing that. If you have multiple crates with the same crate name, but different internally specified html-root-url it already works correctly. It's only the ability to override the html-root-url for a specific instance of the crate that is missing.