@@ -417,34 +417,16 @@ impl Step for Std {
417417 builder. ensure ( compile:: Std { compiler, target } ) ;
418418 let out_dir = builder. stage_out ( compiler, Mode :: Std ) . join ( target) . join ( "doc" ) ;
419419
420- // Here what we're doing is creating a *symlink* (directory junction on
421- // Windows) to the final output location. This is not done as an
422- // optimization but rather for correctness. We've got three trees of
423- // documentation, one for std, one for test, and one for rustc. It's then
424- // our job to merge them all together.
425- //
426- // Unfortunately rustbuild doesn't know nearly as well how to merge doc
427- // trees as rustdoc does itself, so instead of actually having three
428- // separate trees we just have rustdoc output to the same location across
429- // all of them.
430- //
431- // This way rustdoc generates output directly into the output, and rustdoc
432- // will also directly handle merging.
433- let my_out = builder. crate_doc_out ( target) ;
434- t ! ( symlink_dir_force( & builder. config, & my_out, & out_dir) ) ;
435420 t ! ( fs:: copy( builder. src. join( "src/doc/rust.css" ) , out. join( "rust.css" ) ) ) ;
436421
437422 let run_cargo_rustdoc_for = |package : & str | {
438423 let mut cargo =
439424 builder. cargo ( compiler, Mode :: Std , SourceType :: InTree , target, "rustdoc" ) ;
440425 compile:: std_cargo ( builder, target, compiler. stage , & mut cargo) ;
441426
442- cargo. arg ( "-p" ) . arg ( package) ;
443- // Create all crate output directories first to make sure rustdoc uses
444- // relative links.
445- // FIXME: Cargo should probably do this itself.
446- t ! ( fs:: create_dir_all( out_dir. join( package) ) ) ;
447427 cargo
428+ . arg ( "-p" )
429+ . arg ( package)
448430 . arg ( "--" )
449431 . arg ( "--markdown-css" )
450432 . arg ( "rust.css" )
@@ -462,11 +444,17 @@ impl Step for Std {
462444 // folder structure, that would also build internal crates that we do
463445 // not want to show in documentation. These crates will later be visited
464446 // by the rustc step, so internal documentation will show them.
465- let krates = [ "alloc" , "core" , "std" , "proc_macro" , "test" ] ;
447+ //
448+ // Note that the order here is important! The crates need to be
449+ // processed starting from the leaves, otherwise rustdoc will not
450+ // create correct links between crates because rustdoc depends on the
451+ // existence of the output directories to know if it should be a local
452+ // or remote link.
453+ let krates = [ "core" , "alloc" , "std" , "proc_macro" , "test" ] ;
466454 for krate in & krates {
467455 run_cargo_rustdoc_for ( krate) ;
468456 }
469- builder. cp_r ( & my_out , & out) ;
457+ builder. cp_r ( & out_dir , & out) ;
470458
471459 // Look for src/libstd, src/libcore etc in the `x.py doc` arguments and
472460 // open the corresponding rendered docs.
@@ -529,8 +517,11 @@ impl Step for Rustc {
529517 // Build rustc.
530518 builder. ensure ( compile:: Rustc { compiler, target } ) ;
531519
532- // We do not symlink to the same shared folder that already contains std library
533- // documentation from previous steps as we do not want to include that.
520+ // This uses a shared directory so that librustdoc documentation gets
521+ // correctly built and merged with the rustc documentation. This is
522+ // needed because rustdoc is built in a different directory from
523+ // rustc. rustdoc needs to be able to see everything, for example when
524+ // merging the search index, or generating local (relative) links.
534525 let out_dir = builder. stage_out ( compiler, Mode :: Rustc ) . join ( target) . join ( "doc" ) ;
535526 t ! ( symlink_dir_force( & builder. config, & out, & out_dir) ) ;
536527
0 commit comments