Skip to content

Commit c28ee60

Browse files
committed
Fix bugs in doc refactor
- Switch from `cargo rustdoc` to `cargo doc` This allows passing `-p` to multiple packages. - Remove `OsStr` support It doesn't work with RUSTDOCFLAGS, and we don't support non-utf8 paths anyway. - Pass `-p std` for each crate in the standard library By default cargo only documents the top-level crate, which is `sysroot` and has no docs.
1 parent 71770d5 commit c28ee60

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

src/bootstrap/doc.rs

+40-25
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! Everything here is basically just a shim around calling either `rustbook` or
88
//! `rustdoc`.
99
10-
use std::ffi::OsStr;
1110
use std::fs;
1211
use std::io;
1312
use std::path::{Path, PathBuf};
@@ -471,20 +470,21 @@ impl Step for Std {
471470
builder.ensure(SharedAssets { target: self.target });
472471
}
473472

474-
let index_page = builder.src.join("src/doc/index.md").into_os_string();
473+
let index_page = builder
474+
.src
475+
.join("src/doc/index.md")
476+
.into_os_string()
477+
.into_string()
478+
.expect("non-utf8 paths are unsupported");
475479
let mut extra_args = match self.format {
476-
DocumentationFormat::HTML => vec![
477-
OsStr::new("--markdown-css"),
478-
OsStr::new("rust.css"),
479-
OsStr::new("--markdown-no-toc"),
480-
OsStr::new("--index-page"),
481-
&index_page,
482-
],
483-
DocumentationFormat::JSON => vec![OsStr::new("--output-format"), OsStr::new("json")],
480+
DocumentationFormat::HTML => {
481+
vec!["--markdown-css", "rust.css", "--markdown-no-toc", "--index-page", &index_page]
482+
}
483+
DocumentationFormat::JSON => vec!["--output-format", "json"],
484484
};
485485

486486
if !builder.config.docs_minification {
487-
extra_args.push(OsStr::new("--disable-minification"));
487+
extra_args.push("--disable-minification");
488488
}
489489

490490
doc_std(builder, self.format, stage, target, &out, &extra_args, &self.crates);
@@ -549,7 +549,7 @@ fn doc_std(
549549
stage: u32,
550550
target: TargetSelection,
551551
out: &Path,
552-
extra_args: &[&OsStr],
552+
extra_args: &[&str],
553553
requested_crates: &[String],
554554
) {
555555
if builder.no_std(target) == Some(true) {
@@ -574,24 +574,39 @@ fn doc_std(
574574
// as a function parameter.
575575
let out_dir = target_dir.join(target.triple).join("doc");
576576

577-
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc");
577+
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "doc");
578578
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
579-
cargo.arg("--target-dir").arg(&*target_dir.to_string_lossy()).arg("-Zskip-rustdoc-fingerprint");
579+
cargo
580+
.arg("--no-deps")
581+
.arg("--target-dir")
582+
.arg(&*target_dir.to_string_lossy())
583+
.arg("-Zskip-rustdoc-fingerprint")
584+
.rustdocflag("-Z")
585+
.rustdocflag("unstable-options")
586+
.rustdocflag("--resource-suffix")
587+
.rustdocflag(&builder.version);
588+
for arg in extra_args {
589+
cargo.rustdocflag(arg);
590+
}
580591

581-
for krate in requested_crates {
582-
cargo.arg("-p").arg(krate);
592+
if builder.config.library_docs_private_items {
593+
cargo.rustdocflag("--document-private-items").rustdocflag("--document-hidden-items");
583594
}
584595

585-
cargo
586-
.arg("--")
587-
.arg("-Z")
588-
.arg("unstable-options")
589-
.arg("--resource-suffix")
590-
.arg(&builder.version)
591-
.args(extra_args);
596+
// HACK: because we use `--manifest-path library/sysroot/Cargo.toml`, cargo thinks we only want to document that specific crate, not its dependencies.
597+
// Override its default.
598+
let built_crates = if requested_crates.is_empty() {
599+
builder
600+
.in_tree_crates("sysroot", None)
601+
.into_iter()
602+
.map(|krate| krate.name.to_string())
603+
.collect()
604+
} else {
605+
requested_crates.to_vec()
606+
};
592607

593-
if builder.config.library_docs_private_items {
594-
cargo.arg("--document-private-items").arg("--document-hidden-items");
608+
for krate in built_crates {
609+
cargo.arg("-p").arg(krate);
595610
}
596611

597612
builder.run(&mut cargo.into());

0 commit comments

Comments
 (0)