diff --git a/src/compiler/compilation.rs b/src/compiler/compilation.rs index 5e4e335cf1b..7af0e7e4101 100644 --- a/src/compiler/compilation.rs +++ b/src/compiler/compilation.rs @@ -5,6 +5,7 @@ use std::collections::BTreeSet; use std::ffi::{OsStr, OsString}; use std::path::Path; use std::path::PathBuf; +use std::rc::Rc; use cargo_platform::CfgExpr; use cargo_util::{ProcessBuilder, paths}; @@ -117,6 +118,9 @@ pub struct Compilation<'gctx> { /// See `-Zrustdoc-mergeable-info` for more. pub rustdoc_fingerprints: Option>, + /// Extra flags to pass to rustdoc for each host or target. + pub rustdocflags: HashMap>, + /// The target host triple. pub host: String, @@ -145,6 +149,12 @@ impl<'gctx> Compilation<'gctx> { let primary_rustc_process = bcx.build_config.primary_unit_rustc.clone(); let rustc_workspace_wrapper_process = bcx.rustc().workspace_process(); let host = bcx.host_triple().to_string(); + let sysroot_target_libdir = get_sysroot_target_libdir(bcx)?; + let rustdocflags = bcx + .all_kinds + .iter() + .map(|&kind| (kind, bcx.target_data.info(kind).rustdocflags.clone())) + .collect(); // When `target-applies-to-host=false`, and without `--target`, // there will be only `CompileKind::Host` in requested_kinds. @@ -183,7 +193,7 @@ impl<'gctx> Compilation<'gctx> { native_dirs: BTreeSet::new(), root_output: HashMap::default(), deps_output: HashMap::default(), - sysroot_target_libdir: get_sysroot_target_libdir(bcx)?, + sysroot_target_libdir, tests: Vec::new(), binaries: Vec::new(), cdylibs: Vec::new(), @@ -191,6 +201,7 @@ impl<'gctx> Compilation<'gctx> { extra_env: HashMap::default(), to_doc_test: Vec::new(), rustdoc_fingerprints: None, + rustdocflags, gctx: bcx.gctx, host, rustc_process, diff --git a/src/compiler/fingerprint/rustdoc.rs b/src/compiler/fingerprint/rustdoc.rs index 42e7d4640fd..11336b55ee6 100644 --- a/src/compiler/fingerprint/rustdoc.rs +++ b/src/compiler/fingerprint/rustdoc.rs @@ -25,13 +25,13 @@ struct RustdocFingerprintJson { /// Structure used to deal with Rustdoc fingerprinting /// /// This is important because the `.js`/`.html` & `.css` files -/// that are generated by Rustc don't have any versioning yet +/// that are generated by Rustdoc don't have any versioning yet /// (see ). /// Therefore, we can end up with weird bugs and behaviours /// if we mix different versions of these files. /// /// We need to make sure that if there were any previous docs already compiled, -/// they were compiled with the same Rustc version that we're currently using. +/// they were compiled with the same Rustdoc version that we're currently using. /// Otherwise we must remove the `doc/` folder and compile again forcing a rebuild. #[derive(Debug)] pub struct RustdocFingerprint { diff --git a/src/ops/cargo_doc.rs b/src/ops/cargo_doc.rs index 9de066dcf45..f088ae8ad33 100644 --- a/src/ops/cargo_doc.rs +++ b/src/ops/cargo_doc.rs @@ -158,6 +158,7 @@ fn merge_cross_crate_info(ws: &Workspace<'_>, compilation: &Compilation<'_>) -> cmd.arg("-o") .arg(rustdoc_artifact_dir.as_path_unlocked()) .arg("-Zunstable-options"); + cmd.args(&compilation.rustdocflags[kind]); for parts_dir in doc_parts_dirs { let mut include_arg = OsString::from("--read-doc-meta-dir="); include_arg.push(parts_dir); diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 5449e8084c7..89cc255ff81 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -3283,6 +3283,32 @@ fn mergeable_info_with_deps() { ); } +#[cargo_test(nightly, reason = "rustdoc mergeable crate info is unstable")] +fn mergeable_info_with_rustdocflags() { + let p = project() + .file("Cargo.toml", &basic_lib_manifest("foo")) + .file("src/lib.rs", "pub fn foo() {}") + .build(); + + p.cargo("doc -v -Zrustdoc-mergeable-info") + .env( + "RUSTDOCFLAGS", + "--markdown-playground-url=example.com", + ) + .masquerade_as_nightly_cargo(&["rustdoc-mergeable-info"]) + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.5.0 ([ROOT]/foo) +[RUNNING] `rustdoc [..]--crate-name foo [..]-o [ROOT]/foo/target/doc [..]-Zunstable-options --write-doc-meta-dir=[ROOT]/foo/target/debug/build/foo-[HASH]/out [..]--markdown-playground-url=example.com --crate-version 0.5.0` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[MERGING] 1 doc for host +[RUNNING] `rustdoc -o [ROOT]/foo/target/doc -Zunstable-options --markdown-playground-url=example.com --read-doc-meta-dir=[ROOT]/foo/target/debug/build/foo-[HASH]/out` +[FINISHED] documentation merge in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) + .run(); +} + #[cargo_test(nightly, reason = "rustdoc mergeable crate info is unstable")] fn mergeable_info_no_deps() { let p = project()