Skip to content

Commit 178652a

Browse files
committed
Add support to rustbuild for a 'rustc docs' component tarball
1 parent a04b88d commit 178652a

File tree

4 files changed

+178
-41
lines changed

4 files changed

+178
-41
lines changed

src/bootstrap/builder.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,13 @@ impl<'a> Builder<'a> {
316316
test::Rustfmt, test::Miri, test::Clippy, test::RustdocJS, test::RustdocTheme),
317317
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
318318
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
319-
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
320-
doc::Reference, doc::Rustdoc, doc::RustByExample, doc::CargoBook),
321-
Kind::Dist => describe!(dist::Docs, dist::Mingw, dist::Rustc, dist::DebuggerScripts,
322-
dist::Std, dist::Analysis, dist::Src, dist::PlainSourceTarball, dist::Cargo,
323-
dist::Rls, dist::Rustfmt, dist::Extended, dist::HashSign),
319+
doc::Standalone, doc::Std, doc::Test, doc::WhitelistedRustc, doc::Rustc,
320+
doc::ErrorIndex, doc::Nomicon, doc::Reference, doc::Rustdoc, doc::RustByExample,
321+
doc::CargoBook),
322+
Kind::Dist => describe!(dist::Docs, dist::RustcDocs, dist::Mingw, dist::Rustc,
323+
dist::DebuggerScripts, dist::Std, dist::Analysis, dist::Src,
324+
dist::PlainSourceTarball, dist::Cargo, dist::Rls, dist::Rustfmt, dist::Extended,
325+
dist::HashSign),
324326
Kind::Install => describe!(install::Docs, install::Std, install::Cargo, install::Rls,
325327
install::Rustfmt, install::Analysis, install::Src, install::Rustc),
326328
}

src/bootstrap/dist.rs

+62-7
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Step for Docs {
102102

103103
let dst = image.join("share/doc/rust/html");
104104
t!(fs::create_dir_all(&dst));
105-
let src = build.out.join(host).join("doc");
105+
let src = build.doc_out(host);
106106
cp_r(&src, &dst);
107107

108108
let mut cmd = rust_installer(builder);
@@ -120,14 +120,69 @@ impl Step for Docs {
120120
build.run(&mut cmd);
121121
t!(fs::remove_dir_all(&image));
122122

123-
// As part of this step, *also* copy the docs directory to a directory which
124-
// buildbot typically uploads.
125-
if host == build.build {
126-
let dst = distdir(build).join("doc").join(build.rust_package_vers());
127-
t!(fs::create_dir_all(&dst));
128-
cp_r(&src, &dst);
123+
distdir(build).join(format!("{}-{}.tar.gz", name, host))
124+
}
125+
}
126+
127+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
128+
pub struct RustcDocs {
129+
pub stage: u32,
130+
pub host: Interned<String>,
131+
}
132+
133+
impl Step for RustcDocs {
134+
type Output = PathBuf;
135+
const DEFAULT: bool = true;
136+
137+
fn should_run(run: ShouldRun) -> ShouldRun {
138+
run.path("src/librustc")
139+
}
140+
141+
fn make_run(run: RunConfig) {
142+
run.builder.ensure(RustcDocs {
143+
stage: run.builder.top_stage,
144+
host: run.target,
145+
});
146+
}
147+
148+
/// Builds the `rustc-docs` installer component.
149+
fn run(self, builder: &Builder) -> PathBuf {
150+
let build = builder.build;
151+
let host = self.host;
152+
153+
let name = pkgname(build, "rustc-docs");
154+
155+
println!("Dist compiler docs ({})", host);
156+
if !build.config.compiler_docs {
157+
println!("\tskipping - compiler docs disabled");
158+
return distdir(build).join(format!("{}-{}.tar.gz", name, host));
129159
}
130160

161+
builder.default_doc(None);
162+
163+
let image = tmpdir(build).join(format!("{}-{}-image", name, host));
164+
let _ = fs::remove_dir_all(&image);
165+
166+
let dst = image.join("share/doc/rustc/html");
167+
t!(fs::create_dir_all(&dst));
168+
let src = build.compiler_doc_out(host);
169+
cp_r(&src, &dst);
170+
171+
let mut cmd = rust_installer(builder);
172+
cmd.arg("generate")
173+
.arg("--product-name=Rustc-Documentation")
174+
.arg("--rel-manifest-dir=rustlib")
175+
.arg("--success-message=Rustc-documentation-is-installed.")
176+
.arg("--image-dir").arg(&image)
177+
.arg("--work-dir").arg(&tmpdir(build))
178+
.arg("--output-dir").arg(&distdir(build))
179+
.arg(format!("--package-name={}-{}", name, host))
180+
.arg("--component-name=rustc-docs")
181+
.arg("--legacy-manifest-dirs=rustlib,cargo")
182+
.arg("--bulk-dirs=share/doc/rustc/html");
183+
build.run(&mut cmd);
184+
t!(fs::remove_dir_all(&image));
185+
131186
distdir(build).join(format!("{}-{}.tar.gz", name, host))
132187
}
133188
}

src/bootstrap/doc.rs

+104-29
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,17 @@ impl Step for Std {
483483
let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "doc");
484484
compile::std_cargo(builder, &compiler, target, &mut cargo);
485485

486-
// We don't want to build docs for internal std dependencies unless
487-
// in compiler-docs mode. When not in that mode, we whitelist the crates
488-
// for which docs must be built.
489-
if !build.config.compiler_docs {
490-
cargo.arg("--no-deps");
491-
for krate in &["alloc", "core", "std", "std_unicode"] {
492-
cargo.arg("-p").arg(krate);
493-
// Create all crate output directories first to make sure rustdoc uses
494-
// relative links.
495-
// FIXME: Cargo should probably do this itself.
496-
t!(fs::create_dir_all(out_dir.join(krate)));
497-
}
486+
// Keep a whitelist so we do not build internal stdlib crates, these will be
487+
// build by the rustc step later if enabled.
488+
cargo.arg("--no-deps");
489+
for krate in &["alloc", "core", "std", "std_unicode"] {
490+
cargo.arg("-p").arg(krate);
491+
// Create all crate output directories first to make sure rustdoc uses
492+
// relative links.
493+
// FIXME: Cargo should probably do this itself.
494+
t!(fs::create_dir_all(out_dir.join(krate)));
498495
}
499496

500-
501497
build.run(&mut cargo);
502498
cp_r(&my_out, &out);
503499
}
@@ -563,6 +559,81 @@ impl Step for Test {
563559
}
564560
}
565561

562+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
563+
pub struct WhitelistedRustc {
564+
stage: u32,
565+
target: Interned<String>,
566+
}
567+
568+
impl Step for WhitelistedRustc {
569+
type Output = ();
570+
const DEFAULT: bool = true;
571+
const ONLY_HOSTS: bool = true;
572+
573+
fn should_run(run: ShouldRun) -> ShouldRun {
574+
let builder = run.builder;
575+
run.krate("rustc-main").default_condition(builder.build.config.docs)
576+
}
577+
578+
fn make_run(run: RunConfig) {
579+
run.builder.ensure(WhitelistedRustc {
580+
stage: run.builder.top_stage,
581+
target: run.target,
582+
});
583+
}
584+
585+
/// Generate whitelisted compiler crate documentation.
586+
///
587+
/// This will generate all documentation for crates that are whitelisted
588+
/// to be included in the standard documentation. This documentation is
589+
/// included in the standard Rust documentation, so we should always
590+
/// document it and symlink to merge with the rest of the std and test
591+
/// documentation. We don't build other compiler documentation
592+
/// here as we want to be able to keep it separate from the standard
593+
/// documentation. This is largely just a wrapper around `cargo doc`.
594+
fn run(self, builder: &Builder) {
595+
let build = builder.build;
596+
let stage = self.stage;
597+
let target = self.target;
598+
println!("Documenting stage{} whitelisted compiler ({})", stage, target);
599+
let out = build.doc_out(target);
600+
t!(fs::create_dir_all(&out));
601+
let compiler = builder.compiler(stage, build.build);
602+
let rustdoc = builder.rustdoc(compiler.host);
603+
let compiler = if build.force_use_stage1(compiler, target) {
604+
builder.compiler(1, compiler.host)
605+
} else {
606+
compiler
607+
};
608+
609+
// Build libstd docs so that we generate relative links
610+
builder.ensure(Std { stage, target });
611+
612+
builder.ensure(compile::Rustc { compiler, target });
613+
let out_dir = build.stage_out(compiler, Mode::Librustc)
614+
.join(target).join("doc");
615+
616+
// See docs in std above for why we symlink
617+
let my_out = build.crate_doc_out(target);
618+
build.clear_if_dirty(&my_out, &rustdoc);
619+
t!(symlink_dir_force(&my_out, &out_dir));
620+
621+
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "doc");
622+
compile::rustc_cargo(build, &mut cargo);
623+
624+
// We don't want to build docs for internal compiler dependencies in this
625+
// step (there is another step for that). Therefore, we whitelist the crates
626+
// for which docs must be built.
627+
cargo.arg("--no-deps");
628+
for krate in &["proc_macro"] {
629+
cargo.arg("-p").arg(krate);
630+
}
631+
632+
build.run(&mut cargo);
633+
cp_r(&my_out, &out);
634+
}
635+
}
636+
566637
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
567638
pub struct Rustc {
568639
stage: u32,
@@ -586,16 +657,18 @@ impl Step for Rustc {
586657
});
587658
}
588659

589-
/// Generate all compiler documentation.
660+
/// Generate compiler documentation.
590661
///
591-
/// This will generate all documentation for the compiler libraries and their
592-
/// dependencies. This is largely just a wrapper around `cargo doc`.
662+
/// This will generate all documentation for compiler and dependencies.
663+
/// Compiler documentation is distributed separately, so we make sure
664+
/// we do not merge it with the other documentation from std, test and
665+
/// proc_macros. This is largely just a wrapper around `cargo doc`.
593666
fn run(self, builder: &Builder) {
594667
let build = builder.build;
595668
let stage = self.stage;
596669
let target = self.target;
597670
println!("Documenting stage{} compiler ({})", stage, target);
598-
let out = build.doc_out(target);
671+
let out = build.compiler_doc_out(target);
599672
t!(fs::create_dir_all(&out));
600673
let compiler = builder.compiler(stage, build.build);
601674
let rustdoc = builder.rustdoc(compiler.host);
@@ -605,6 +678,11 @@ impl Step for Rustc {
605678
compiler
606679
};
607680

681+
if !build.config.compiler_docs {
682+
println!("\tskipping - compiler docs disabled");
683+
return;
684+
}
685+
608686
// Build libstd docs so that we generate relative links
609687
builder.ensure(Std { stage, target });
610688

@@ -613,25 +691,22 @@ impl Step for Rustc {
613691
.join(target).join("doc");
614692

615693
// See docs in std above for why we symlink
694+
//
695+
// This step must happen after other documentation steps. This
696+
// invariant ensures that compiler documentation is not included
697+
// in the standard documentation tarballs but that all the
698+
// documentation from the standard documentation tarballs is included
699+
// in the compiler documentation tarball.
616700
let my_out = build.crate_doc_out(target);
617701
build.clear_if_dirty(&my_out, &rustdoc);
618702
t!(symlink_dir_force(&my_out, &out_dir));
619703

620704
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "doc");
621705
compile::rustc_cargo(build, &mut cargo);
622706

623-
if build.config.compiler_docs {
624-
// src/rustc/Cargo.toml contains a bin crate called rustc which
625-
// would otherwise overwrite the docs for the real rustc lib crate.
626-
cargo.arg("-p").arg("rustc_driver");
627-
} else {
628-
// Like with libstd above if compiler docs aren't enabled then we're not
629-
// documenting internal dependencies, so we have a whitelist.
630-
cargo.arg("--no-deps");
631-
for krate in &["proc_macro"] {
632-
cargo.arg("-p").arg(krate);
633-
}
634-
}
707+
// src/rustc/Cargo.toml contains a bin crate called rustc which
708+
// would otherwise overwrite the docs for the real rustc lib crate.
709+
cargo.arg("-p").arg("rustc_driver");
635710

636711
build.run(&mut cargo);
637712
cp_r(&my_out, &out);

src/bootstrap/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ impl Build {
511511
self.out.join(&*target).join("doc")
512512
}
513513

514+
/// Output directory for all documentation for a target
515+
fn compiler_doc_out(&self, target: Interned<String>) -> PathBuf {
516+
self.out.join(&*target).join("compiler-doc")
517+
}
518+
514519
/// Output directory for some generated md crate documentation for a target (temporary)
515520
fn md_doc_out(&self, target: Interned<String>) -> Interned<PathBuf> {
516521
INTERNER.intern_path(self.out.join(&*target).join("md-doc"))

0 commit comments

Comments
 (0)