@@ -1454,8 +1454,11 @@ impl Step for ErrorIndex {
1454
1454
}
1455
1455
1456
1456
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 } ) ;
1459
1462
}
1460
1463
1461
1464
/// Runs the error index generator tool to execute the tests located in the error
@@ -1467,22 +1470,23 @@ impl Step for ErrorIndex {
1467
1470
fn run ( self , builder : & Builder < ' _ > ) {
1468
1471
let compiler = self . compiler ;
1469
1472
1470
- builder. ensure ( compile:: Std { compiler, target : compiler. host } ) ;
1471
-
1472
1473
let dir = testdir ( builder, compiler. host ) ;
1473
1474
t ! ( fs:: create_dir_all( & dir) ) ;
1474
1475
let output = dir. join ( "error-index.md" ) ;
1475
1476
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) ;
1481
1479
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) ) ;
1483
1486
let _time = util:: timeit ( & builder) ;
1484
1487
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) ;
1486
1490
}
1487
1491
}
1488
1492
@@ -1797,9 +1801,13 @@ impl Step for CrateRustdoc {
1797
1801
1798
1802
fn run ( self , builder : & Builder < ' _ > ) {
1799
1803
let test_kind = self . test_kind ;
1804
+ let target = self . host ;
1800
1805
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) ;
1803
1811
builder. ensure ( compile:: Rustc { compiler, target } ) ;
1804
1812
1805
1813
let mut cargo = tool:: prepare_tool_cargo (
@@ -1825,6 +1833,32 @@ impl Step for CrateRustdoc {
1825
1833
cargo. arg ( "'-Ctarget-feature=-crt-static'" ) ;
1826
1834
}
1827
1835
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
+
1828
1862
if !builder. config . verbose_tests {
1829
1863
cargo. arg ( "--quiet" ) ;
1830
1864
}
0 commit comments