diff --git a/crates/metadata/lib.rs b/crates/metadata/lib.rs index 8ceeee651..656c9975f 100644 --- a/crates/metadata/lib.rs +++ b/crates/metadata/lib.rs @@ -229,7 +229,8 @@ impl Metadata { /// For example, the links may point somewhere different than they would on docs.rs. /// However, rustdoc will see exactly the same code as it would on docs.rs, even counting `cfg`s. pub fn cargo_args(&self, additional_args: &[String], rustdoc_args: &[String]) -> Vec { - let mut cargo_args: Vec = vec!["rustdoc".into(), "--lib".into()]; + let mut cargo_args: Vec = + vec!["rustdoc".into(), "--lib".into(), "-Zrustdoc-map".into()]; if let Some(features) = &self.features { cargo_args.push("--features".into()); @@ -521,7 +522,12 @@ mod test_calculations { use super::*; fn default_cargo_args() -> Vec { - vec!["rustdoc".into(), "--lib".into(), "--".into()] + vec![ + "rustdoc".into(), + "--lib".into(), + "-Zrustdoc-map".into(), + "--".into(), + ] } #[test] @@ -574,6 +580,7 @@ mod test_calculations { let expected_args = vec![ "rustdoc".into(), "--lib".into(), + "-Zrustdoc-map".into(), "--features".into(), String::new(), "--".into(), @@ -588,6 +595,7 @@ mod test_calculations { let expected_args = vec![ String::from("rustdoc"), "--lib".into(), + "-Zrustdoc-map".into(), "--features".into(), "some_feature".into(), "--".into(), @@ -602,6 +610,7 @@ mod test_calculations { let expected_args = vec![ String::from("rustdoc"), "--lib".into(), + "-Zrustdoc-map".into(), "--features".into(), "feature1 feature2".into(), "--".into(), @@ -623,6 +632,7 @@ mod test_calculations { let expected_args = vec![ String::from("rustdoc"), "--lib".into(), + "-Zrustdoc-map".into(), "--".into(), "-Z".into(), "unstable-options".into(), @@ -641,6 +651,7 @@ mod test_calculations { let expected_args = vec![ String::from("rustdoc"), "--lib".into(), + "-Zrustdoc-map".into(), "-Z".into(), "unstable-options".into(), "--config".into(), diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index ce53f771e..98850ece6 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -518,16 +518,6 @@ impl RustwideBuilder { let mut rustdoc_flags = Vec::new(); - for dep in &cargo_metadata.root_dependencies() { - rustdoc_flags.push("--extern-html-root-url".to_string()); - rustdoc_flags.push(format!( - "{}=https://docs.rs/{}/{}", - dep.name.replace("-", "_"), - dep.name, - dep.version - )); - } - rustdoc_flags.extend(vec![ "--resource-suffix".to_string(), format!("-{}", parse_rustc_version(&self.rustc_version)?), @@ -589,6 +579,12 @@ impl RustwideBuilder { // Add docs.rs specific arguments let mut cargo_args = Vec::new(); + // Show the command line Rustdoc is invoked with + cargo_args.push("--verbose".into()); + // We know that `metadata` unconditionally passes `-Z rustdoc-map`. + // Don't copy paste this, since that fact is not stable and may change in the future. + cargo_args.push("-Zunstable-options".into()); + cargo_args.push(r#"--config=doc.extern-map.registries.crates-io="https://docs.rs""#.into()); if let Some(cpu_limit) = self.config.build_cpu_limit { cargo_args.push(format!("-j{}", cpu_limit)); } diff --git a/src/utils/cargo_metadata.rs b/src/utils/cargo_metadata.rs index c35337ac3..c3573666b 100644 --- a/src/utils/cargo_metadata.rs +++ b/src/utils/cargo_metadata.rs @@ -1,13 +1,11 @@ use crate::error::Result; use rustwide::{cmd::Command, Toolchain, Workspace}; use serde::{Deserialize, Serialize}; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use std::path::Path; pub(crate) struct CargoMetadata { - packages: HashMap, - deps_graph: HashMap>, - root_id: String, + root: Package, } impl CargoMetadata { @@ -31,34 +29,18 @@ impl CargoMetadata { )); }; - // Convert from Vecs to HashMaps and HashSets to get more efficient lookups + let root = metadata.resolve.root; Ok(CargoMetadata { - packages: metadata + root: metadata .packages .into_iter() - .map(|pkg| (pkg.id.clone(), pkg)) - .collect(), - deps_graph: metadata - .resolve - .nodes - .into_iter() - .map(|node| (node.id, node.deps.into_iter().map(|d| d.pkg).collect())) - .collect(), - root_id: metadata.resolve.root, + .find(|pkg| pkg.id == root) + .unwrap(), }) } - pub(crate) fn root_dependencies(&self) -> Vec<&Package> { - let ids = &self.deps_graph[&self.root_id]; - self.packages - .iter() - .filter(|(id, _pkg)| ids.contains(id.as_str())) - .map(|(_id, pkg)| pkg) - .collect() - } - pub(crate) fn root(&self) -> &Package { - &self.packages[&self.root_id] + &self.root } }