Skip to content

Commit 5cc1baa

Browse files
committed
Auto merge of #43482 - Mark-Simulacrum:single-rustdoc, r=alexcrichton
Compile rustdoc on-demand Fixes #43284, fixes #38318, and fixes #39505. Doesn't directly help with #42686, since we need to rebuild just as much. In fact, this hurts it, since `./x.py doc --stage 0` will now fail. I'm not sure if it did before, but with these changes it runs into the problem where we attempt to use artifacts from bootstrap rustc with a non-bootstrap rustdoc, running into version conflicts. I believe this is solvable, but leaving for a future PR. This means that rustdoc will no longer be compiled when compiling rustc, by default. However, it is still built from `./x.py build` (for hosts, but not targets, since we don't produce compiler toolchains for them) and will be built for doc tests and crate tests. After this, the recommended workflow if you want a rustdoc is: `./x.py build --stage 1 src/tools/rustdoc` which will give you a working rustdoc in `build/triple/stage1/bin/rustdoc`. Note that you can add `src/libstd` onto the command to compile libstd as well so that the rustdoc can easily compile crates in the wild. `./x.py doc --stage 1 src/libstd` will document `libstd` with a freshly built rustdoc (if necessary), and will not rebuild rustc on modifications to rustdoc. r? @alexcrichton
2 parents 0565653 + 9ee877b commit 5cc1baa

File tree

18 files changed

+181
-144
lines changed

18 files changed

+181
-144
lines changed

Diff for: src/Cargo.lock

+10-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ members = [
1616
"tools/remote-test-server",
1717
"tools/rust-installer",
1818
"tools/cargo",
19+
"tools/rustdoc",
1920
"tools/rls",
2021
# FIXME(https://github.com/rust-lang/cargo/issues/4089): move these to exclude
2122
"tools/rls/test_data/borrow_error",

Diff for: src/bootstrap/builder.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'a> Builder<'a> {
256256
compile::StartupObjects, tool::BuildManifest, tool::Rustbook, tool::ErrorIndex,
257257
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
258258
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
259-
tool::RustInstaller, tool::Cargo, tool::Rls),
259+
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc),
260260
Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
261261
check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Linkcheck,
262262
check::Cargotest, check::Cargo, check::Rls, check::Docs, check::ErrorIndex,
@@ -412,12 +412,23 @@ impl<'a> Builder<'a> {
412412
}
413413
}
414414

415-
/// Get the `rustdoc` executable next to the specified compiler
416415
pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
417-
let mut rustdoc = self.rustc(compiler);
418-
rustdoc.pop();
419-
rustdoc.push(exe("rustdoc", &compiler.host));
420-
rustdoc
416+
self.ensure(tool::Rustdoc { target_compiler: compiler })
417+
}
418+
419+
pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
420+
let mut cmd = Command::new(&self.out.join("bootstrap/debug/rustdoc"));
421+
cmd
422+
.env("RUSTC_STAGE", compiler.stage.to_string())
423+
.env("RUSTC_SYSROOT", if compiler.is_snapshot(&self.build) {
424+
INTERNER.intern_path(self.build.rustc_snapshot_libdir())
425+
} else {
426+
self.sysroot(compiler)
427+
})
428+
.env("RUSTC_LIBDIR", self.sysroot_libdir(compiler, self.build.build))
429+
.env("CFG_RELEASE_CHANNEL", &self.build.config.channel)
430+
.env("RUSTDOC_REAL", self.rustdoc(compiler));
431+
cmd
421432
}
422433

423434
/// Prepares an invocation of `cargo` to be run.
@@ -469,7 +480,11 @@ impl<'a> Builder<'a> {
469480
.env("RUSTC_LIBDIR", self.rustc_libdir(compiler))
470481
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
471482
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
472-
.env("RUSTDOC_REAL", self.rustdoc(compiler))
483+
.env("RUSTDOC_REAL", if cmd == "doc" || cmd == "test" {
484+
self.rustdoc(compiler)
485+
} else {
486+
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
487+
})
473488
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
474489

475490
if mode != Mode::Tool {
@@ -560,6 +575,9 @@ impl<'a> Builder<'a> {
560575
// FIXME: should update code to not require this env var
561576
cargo.env("CFG_COMPILER_HOST_TRIPLE", target);
562577

578+
// Set this for all builds to make sure doc builds also get it.
579+
cargo.env("CFG_RELEASE_CHANNEL", &self.build.config.channel);
580+
563581
if self.is_verbose() {
564582
cargo.arg("-v");
565583
}

Diff for: src/bootstrap/check.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Step for Linkcheck {
119119
}
120120

121121
fn make_run(run: RunConfig) {
122-
run.builder.ensure(Linkcheck { host: run.host });
122+
run.builder.ensure(Linkcheck { host: run.target });
123123
}
124124
}
125125

@@ -140,7 +140,7 @@ impl Step for Cargotest {
140140
fn make_run(run: RunConfig) {
141141
run.builder.ensure(Cargotest {
142142
stage: run.builder.top_stage,
143-
host: run.host,
143+
host: run.target,
144144
});
145145
}
146146

@@ -194,7 +194,7 @@ impl Step for Cargo {
194194
let build = builder.build;
195195
let compiler = builder.compiler(self.stage, self.host);
196196

197-
builder.ensure(tool::Cargo { stage: self.stage, target: self.host });
197+
builder.ensure(tool::Cargo { compiler, target: self.host });
198198
let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
199199
cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
200200
if !build.fail_fast {
@@ -240,7 +240,7 @@ impl Step for Rls {
240240
let host = self.host;
241241
let compiler = builder.compiler(stage, host);
242242

243-
builder.ensure(tool::Rls { stage: self.stage, target: self.host });
243+
builder.ensure(tool::Rls { compiler, target: self.host });
244244
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
245245
cargo.arg("--manifest-path").arg(build.src.join("src/tools/rls/Cargo.toml"));
246246

@@ -562,7 +562,12 @@ impl Step for Compiletest {
562562
cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
563563
cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
564564
cmd.arg("--rustc-path").arg(builder.rustc(compiler));
565-
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
565+
566+
// Avoid depending on rustdoc when we don't need it.
567+
if mode == "rustdoc" || mode == "run-make" {
568+
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
569+
}
570+
566571
cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
567572
cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
568573
cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
@@ -809,8 +814,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
809814
}
810815

811816
println!("doc tests for: {}", markdown.display());
812-
let mut cmd = Command::new(builder.rustdoc(compiler));
813-
builder.add_rustc_lib_path(compiler, &mut cmd);
817+
let mut cmd = builder.rustdoc_cmd(compiler);
814818
build.add_rust_test_threads(&mut cmd);
815819
cmd.arg("--test");
816820
cmd.arg(markdown);
@@ -1165,7 +1169,7 @@ impl Step for RemoteCopyLibs {
11651169
println!("REMOTE copy libs to emulator ({})", target);
11661170
t!(fs::create_dir_all(build.out.join("tmp")));
11671171

1168-
let server = builder.ensure(tool::RemoteTestServer { stage: compiler.stage, target });
1172+
let server = builder.ensure(tool::RemoteTestServer { compiler, target });
11691173

11701174
// Spawn the emulator and wait for it to come online
11711175
let tool = builder.tool_exe(Tool::RemoteTestClient);

Diff for: src/bootstrap/compile.rs

-9
Original file line numberDiff line numberDiff line change
@@ -719,15 +719,6 @@ impl Step for Assemble {
719719
let _ = fs::remove_file(&compiler);
720720
copy(&rustc, &compiler);
721721

722-
// See if rustdoc exists to link it into place
723-
let rustdoc = exe("rustdoc", &*host);
724-
let rustdoc_src = out_dir.join(&rustdoc);
725-
let rustdoc_dst = bindir.join(&rustdoc);
726-
if fs::metadata(&rustdoc_src).is_ok() {
727-
let _ = fs::remove_file(&rustdoc_dst);
728-
copy(&rustdoc_src, &rustdoc_dst);
729-
}
730-
731722
target_compiler
732723
}
733724
}

Diff for: src/bootstrap/dist.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ impl Step for Rustc {
413413
t!(fs::create_dir_all(image.join("bin")));
414414
cp_r(&src.join("bin"), &image.join("bin"));
415415

416+
install(&builder.ensure(tool::Rustdoc { target_compiler: compiler }),
417+
&image.join("bin"), 0o755);
418+
416419
// Copy runtime DLLs needed by the compiler
417420
if libdir != "bin" {
418421
for entry in t!(src.join(libdir).read_dir()).map(|e| t!(e)) {
@@ -963,7 +966,10 @@ impl Step for Cargo {
963966
// Prepare the image directory
964967
t!(fs::create_dir_all(image.join("share/zsh/site-functions")));
965968
t!(fs::create_dir_all(image.join("etc/bash_completion.d")));
966-
let cargo = builder.ensure(tool::Cargo { stage, target });
969+
let cargo = builder.ensure(tool::Cargo {
970+
compiler: builder.compiler(stage, build.build),
971+
target
972+
});
967973
install(&cargo, &image.join("bin"), 0o755);
968974
for man in t!(etc.join("man").read_dir()) {
969975
let man = t!(man);
@@ -1046,7 +1052,10 @@ impl Step for Rls {
10461052
t!(fs::create_dir_all(&image));
10471053

10481054
// Prepare the image directory
1049-
let rls = builder.ensure(tool::Rls { stage, target });
1055+
let rls = builder.ensure(tool::Rls {
1056+
compiler: builder.compiler(stage, build.build),
1057+
target
1058+
});
10501059
install(&rls, &image.join("bin"), 0o755);
10511060
let doc = image.join("share/doc/rls");
10521061
install(&src.join("README.md"), &doc, 0o644);

0 commit comments

Comments
 (0)