@@ -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 }
0 commit comments