Skip to content

Commit ff2f7c5

Browse files
Build rustdoc only at the topmost stage.
This effectively ensures that rustdoc will only ever be built once for any given host. This does not introduce cycles into the build since we only depend on rustdoc from documentation or test steps, which run after the required compiler was built.
1 parent e2b5d7e commit ff2f7c5

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

src/bootstrap/bin/rustdoc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() {
2424
let args = env::args_os().skip(1).collect::<Vec<_>>();
2525
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
2626
let libdir = env::var_os("RUSTC_LIBDIR").expect("RUSTC_LIBDIR was not set");
27-
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
27+
let stage = env::var("RUSTDOC_STAGE").expect("RUSTDOC_STAGE was not set");
2828
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
2929

3030
let mut dylib_path = bootstrap::util::dylib_path();

src/bootstrap/builder.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -412,22 +412,20 @@ impl<'a> Builder<'a> {
412412
}
413413
}
414414

415-
pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
416-
self.ensure(tool::Rustdoc { target_compiler: compiler })
415+
pub fn rustdoc(&self, host: Interned<String>) -> PathBuf {
416+
self.ensure(tool::Rustdoc { host })
417417
}
418418

419-
pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
419+
pub fn rustdoc_cmd(&self, host: Interned<String>) -> Command {
420420
let mut cmd = Command::new(&self.out.join("bootstrap/debug/rustdoc"));
421+
// See rational for top_stage in rustdoc
422+
let compiler = self.compiler(self.top_stage, host);
421423
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-
})
424+
.env("RUSTDOC_STAGE", compiler.stage.to_string())
425+
.env("RUSTC_SYSROOT", self.sysroot(compiler))
428426
.env("RUSTC_LIBDIR", self.sysroot_libdir(compiler, self.build.build))
429427
.env("CFG_RELEASE_CHANNEL", &self.build.config.channel)
430-
.env("RUSTDOC_REAL", self.rustdoc(compiler));
428+
.env("RUSTDOC_REAL", self.rustdoc(compiler.host));
431429
cmd
432430
}
433431

@@ -480,8 +478,9 @@ impl<'a> Builder<'a> {
480478
.env("RUSTC_LIBDIR", self.rustc_libdir(compiler))
481479
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
482480
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
481+
.env("RUSTDOC_STAGE", self.top_stage.to_string())
483482
.env("RUSTDOC_REAL", if cmd == "doc" || cmd == "test" {
484-
self.rustdoc(compiler)
483+
self.rustdoc(compiler.host)
485484
} else {
486485
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
487486
})

src/bootstrap/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl Step for Cargotest {
164164
try_run(build, cmd.arg(&build.initial_cargo)
165165
.arg(&out_dir)
166166
.env("RUSTC", builder.rustc(compiler))
167-
.env("RUSTDOC", builder.rustdoc(compiler)));
167+
.env("RUSTDOC", builder.rustdoc(compiler.host)));
168168
}
169169
}
170170

@@ -565,7 +565,7 @@ impl Step for Compiletest {
565565

566566
// Avoid depending on rustdoc when we don't need it.
567567
if mode == "rustdoc" || mode == "run-make" {
568-
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
568+
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
569569
}
570570

571571
cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
@@ -814,7 +814,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
814814
}
815815

816816
println!("doc tests for: {}", markdown.display());
817-
let mut cmd = builder.rustdoc_cmd(compiler);
817+
let mut cmd = builder.rustdoc_cmd(compiler.host);
818818
build.add_rust_test_threads(&mut cmd);
819819
cmd.arg("--test");
820820
cmd.arg(markdown);

src/bootstrap/dist.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ 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);
416+
install(&builder.rustdoc(compiler.host), &image.join("bin"), 0o755);
418417

419418
// Copy runtime DLLs needed by the compiler
420419
if libdir != "bin" {

src/bootstrap/doc.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String
260260
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
261261
}
262262

263-
let mut cmd = builder.rustdoc_cmd(compiler);
263+
let mut cmd = builder.rustdoc_cmd(compiler.host);
264264

265265
let out = out.join("book");
266266

@@ -343,7 +343,7 @@ impl Step for Standalone {
343343
}
344344

345345
let html = out.join(filename).with_extension("html");
346-
let rustdoc = builder.rustdoc(compiler);
346+
let rustdoc = builder.rustdoc(compiler.host);
347347
if up_to_date(&path, &html) &&
348348
up_to_date(&footer, &html) &&
349349
up_to_date(&favicon, &html) &&
@@ -353,7 +353,7 @@ impl Step for Standalone {
353353
continue
354354
}
355355

356-
let mut cmd = builder.rustdoc_cmd(compiler);
356+
let mut cmd = builder.rustdoc_cmd(compiler.host);
357357
cmd.arg("--html-after-content").arg(&footer)
358358
.arg("--html-before-content").arg(&version_info)
359359
.arg("--html-in-header").arg(&favicon)
@@ -408,7 +408,7 @@ impl Step for Std {
408408
let out = build.doc_out(target);
409409
t!(fs::create_dir_all(&out));
410410
let compiler = builder.compiler(stage, build.build);
411-
let rustdoc = builder.rustdoc(compiler);
411+
let rustdoc = builder.rustdoc(compiler.host);
412412
let compiler = if build.force_use_stage1(compiler, target) {
413413
builder.compiler(1, compiler.host)
414414
} else {
@@ -493,7 +493,7 @@ impl Step for Test {
493493
let out = build.doc_out(target);
494494
t!(fs::create_dir_all(&out));
495495
let compiler = builder.compiler(stage, build.build);
496-
let rustdoc = builder.rustdoc(compiler);
496+
let rustdoc = builder.rustdoc(compiler.host);
497497
let compiler = if build.force_use_stage1(compiler, target) {
498498
builder.compiler(1, compiler.host)
499499
} else {
@@ -554,7 +554,7 @@ impl Step for Rustc {
554554
let out = build.doc_out(target);
555555
t!(fs::create_dir_all(&out));
556556
let compiler = builder.compiler(stage, build.build);
557-
let rustdoc = builder.rustdoc(compiler);
557+
let rustdoc = builder.rustdoc(compiler.host);
558558
let compiler = if build.force_use_stage1(compiler, target) {
559559
builder.compiler(1, compiler.host)
560560
} else {

src/bootstrap/tool.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl Step for RemoteTestServer {
226226

227227
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
228228
pub struct Rustdoc {
229-
pub target_compiler: Compiler,
229+
pub host: Interned<String>,
230230
}
231231

232232
impl Step for Rustdoc {
@@ -240,30 +240,32 @@ impl Step for Rustdoc {
240240

241241
fn make_run(run: RunConfig) {
242242
run.builder.ensure(Rustdoc {
243-
target_compiler: run.builder.compiler(run.builder.top_stage, run.host),
243+
host: run.host,
244244
});
245245
}
246246

247247
fn run(self, builder: &Builder) -> PathBuf {
248-
let target_compiler = self.target_compiler;
249-
let build_compiler = if target_compiler.stage == 0 {
248+
// Always build rustdoc at the top stage; otherwise we rebuild it twice (or more).
249+
let stage = builder.top_stage;
250+
let build_compiler = if stage == 0 {
250251
builder.compiler(0, builder.build.build)
251252
} else {
252253
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
253254
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
254255
// compilers, which isn't what we want.
255-
builder.compiler(target_compiler.stage - 1, builder.build.build)
256+
builder.compiler(stage - 1, builder.build.build)
256257
};
257258

258259
let tool_rustdoc = builder.ensure(ToolBuild {
259260
compiler: build_compiler,
260-
target: target_compiler.host,
261+
target: self.host,
261262
tool: "rustdoc",
262263
mode: Mode::Librustc,
263264
});
264265

265266
// don't create a stage0-sysroot/bin directory.
266-
if target_compiler.stage > 0 {
267+
if stage > 0 {
268+
let target_compiler = builder.compiler(build_compiler.stage + 1, self.host);
267269
let sysroot = builder.sysroot(target_compiler);
268270
let bindir = sysroot.join("bin");
269271
t!(fs::create_dir_all(&bindir));

0 commit comments

Comments
 (0)