Skip to content

Commit 9154863

Browse files
committed
Compile rustdoc less often.
1 parent 0ca7f74 commit 9154863

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
lines changed

src/bootstrap/doc.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ impl Step for Rustc {
518518
let out = builder.compiler_doc_out(target);
519519
t!(fs::create_dir_all(&out));
520520

521-
// Get the correct compiler for this stage.
522-
let compiler = builder.compiler_for(stage, builder.config.build, target);
521+
let compiler = builder.compiler(stage, builder.config.build);
523522

524523
if !builder.config.compiler_docs {
525524
builder.info("\tskipping - compiler/librustdoc docs disabled");
@@ -599,8 +598,7 @@ impl Step for Rustdoc {
599598
let out = builder.compiler_doc_out(target);
600599
t!(fs::create_dir_all(&out));
601600

602-
// Get the correct compiler for this stage.
603-
let compiler = builder.compiler_for(stage, builder.config.build, target);
601+
let compiler = builder.compiler(stage, builder.config.build);
604602

605603
if !builder.config.compiler_docs {
606604
builder.info("\tskipping - compiler/librustdoc docs disabled");
@@ -666,15 +664,15 @@ impl Step for ErrorIndex {
666664
builder.info(&format!("Documenting error index ({})", target));
667665
let out = builder.doc_out(target);
668666
t!(fs::create_dir_all(&out));
669-
let compiler = builder.compiler(2, builder.config.build);
667+
// error_index_generator depends on librustdoc. Use the compiler that
668+
// is normally used to build rustdoc for other documentation so that
669+
// it shares the same artifacts.
670+
let compiler = builder.compiler_for(builder.top_stage, builder.config.build, target);
670671
let mut index = tool::ErrorIndex::command(builder, compiler);
671672
index.arg("html");
672673
index.arg(out.join("error-index.html"));
673674
index.arg(crate::channel::CFG_RELEASE_NUM);
674675

675-
// FIXME: shouldn't have to pass this env var
676-
index.env("CFG_BUILD", &builder.config.build);
677-
678676
builder.run(&mut index);
679677
}
680678
}

src/bootstrap/test.rs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,11 @@ impl Step for ErrorIndex {
14541454
}
14551455

14561456
fn make_run(run: RunConfig<'_>) {
1457-
run.builder
1458-
.ensure(ErrorIndex { compiler: run.builder.compiler(run.builder.top_stage, run.host) });
1457+
// error_index_generator depends on librustdoc. Use the compiler that
1458+
// is normally used to build rustdoc for other tests (like compiletest
1459+
// tests in src/test/rustdoc) so that it shares the same artifacts.
1460+
let compiler = run.builder.compiler_for(run.builder.top_stage, run.host, run.host);
1461+
run.builder.ensure(ErrorIndex { compiler });
14591462
}
14601463

14611464
/// Runs the error index generator tool to execute the tests located in the error
@@ -1467,22 +1470,23 @@ impl Step for ErrorIndex {
14671470
fn run(self, builder: &Builder<'_>) {
14681471
let compiler = self.compiler;
14691472

1470-
builder.ensure(compile::Std { compiler, target: compiler.host });
1471-
14721473
let dir = testdir(builder, compiler.host);
14731474
t!(fs::create_dir_all(&dir));
14741475
let output = dir.join("error-index.md");
14751476

1476-
let mut tool = tool::ErrorIndex::command(
1477-
builder,
1478-
builder.compiler(compiler.stage, builder.config.build),
1479-
);
1480-
tool.arg("markdown").arg(&output).env("CFG_BUILD", &builder.config.build);
1477+
let mut tool = tool::ErrorIndex::command(builder, compiler);
1478+
tool.arg("markdown").arg(&output);
14811479

1482-
builder.info(&format!("Testing error-index stage{}", compiler.stage));
1480+
// Use the rustdoc that was built by self.compiler. This copy of
1481+
// rustdoc is shared with other tests (like compiletest tests in
1482+
// src/test/rustdoc). This helps avoid building rustdoc multiple
1483+
// times.
1484+
let rustdoc_compiler = builder.compiler(builder.top_stage, builder.config.build);
1485+
builder.info(&format!("Testing error-index stage{}", rustdoc_compiler.stage));
14831486
let _time = util::timeit(&builder);
14841487
builder.run_quiet(&mut tool);
1485-
markdown_test(builder, compiler, &output);
1488+
builder.ensure(compile::Std { compiler: rustdoc_compiler, target: rustdoc_compiler.host });
1489+
markdown_test(builder, rustdoc_compiler, &output);
14861490
}
14871491
}
14881492

@@ -1797,9 +1801,13 @@ impl Step for CrateRustdoc {
17971801

17981802
fn run(self, builder: &Builder<'_>) {
17991803
let test_kind = self.test_kind;
1804+
let target = self.host;
18001805

1801-
let compiler = builder.compiler(builder.top_stage, self.host);
1802-
let target = compiler.host;
1806+
// Use the previous stage compiler to reuse the artifacts that are
1807+
// created when running compiletest for src/test/rustdoc. If this used
1808+
// `compiler`, then it would cause rustdoc to be built *again*, which
1809+
// isn't really necessary.
1810+
let compiler = builder.compiler_for(builder.top_stage, target, target);
18031811
builder.ensure(compile::Rustc { compiler, target });
18041812

18051813
let mut cargo = tool::prepare_tool_cargo(
@@ -1825,6 +1833,32 @@ impl Step for CrateRustdoc {
18251833
cargo.arg("'-Ctarget-feature=-crt-static'");
18261834
}
18271835

1836+
// This is needed for running doctests on librustdoc. This is a bit of
1837+
// an unfortunate interaction with how bootstrap works and how cargo
1838+
// sets up the dylib path, and the fact that the doctest (in
1839+
// html/markdown.rs) links to rustc-private libs. For stage1, the
1840+
// compiler host dylibs (in stage1/lib) are not the same as the target
1841+
// dylibs (in stage1/lib/rustlib/...). This is different from a normal
1842+
// rust distribution where they are the same.
1843+
//
1844+
// On the cargo side, normal tests use `target_process` which handles
1845+
// setting up the dylib for a *target* (stage1/lib/rustlib/... in this
1846+
// case). However, for doctests it uses `rustdoc_process` which only
1847+
// sets up the dylib path for the *host* (stage1/lib), which is the
1848+
// wrong directory.
1849+
//
1850+
// It should be considered to just stop running doctests on
1851+
// librustdoc. There is only one test, and it doesn't look too
1852+
// important. There might be other ways to avoid this, but it seems
1853+
// pretty convoluted.
1854+
//
1855+
// See also https://github.com/rust-lang/rust/issues/13983 where the
1856+
// host vs target dylibs for rustdoc are consistently tricky to deal
1857+
// with.
1858+
let mut dylib_path = dylib_path();
1859+
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1860+
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1861+
18281862
if !builder.config.verbose_tests {
18291863
cargo.arg("--quiet");
18301864
}

src/bootstrap/tool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ impl Step for ErrorIndex {
392392
fn make_run(run: RunConfig<'_>) {
393393
// Compile the error-index in the same stage as rustdoc to avoid
394394
// recompiling rustdoc twice if we can.
395-
let stage = if run.builder.top_stage >= 2 { run.builder.top_stage } else { 0 };
396-
run.builder
397-
.ensure(ErrorIndex { compiler: run.builder.compiler(stage, run.builder.config.build) });
395+
let host = run.builder.config.build;
396+
let compiler = run.builder.compiler_for(run.builder.top_stage, host, host);
397+
run.builder.ensure(ErrorIndex { compiler });
398398
}
399399

400400
fn run(self, builder: &Builder<'_>) -> PathBuf {

0 commit comments

Comments
 (0)