@@ -9,7 +9,8 @@ use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun,
99use crate :: core:: config:: TargetSelection ;
1010use crate :: utils:: channel:: GitInfo ;
1111use crate :: utils:: exec:: BootstrapCommand ;
12- use crate :: utils:: helpers:: { add_dylib_path, exe, t} ;
12+ use crate :: utils:: helpers:: git;
13+ use crate :: utils:: helpers:: { add_dylib_path, exe, get_closest_merge_base_commit, t} ;
1314use crate :: Compiler ;
1415use crate :: Mode ;
1516use crate :: { gha, Kind } ;
@@ -553,6 +554,53 @@ impl Step for Rustdoc {
553554 }
554555 let target = target_compiler. host ;
555556
557+ let bin_rustdoc = || {
558+ let sysroot = builder. sysroot ( target_compiler) ;
559+ let bindir = sysroot. join ( "bin" ) ;
560+ t ! ( fs:: create_dir_all( & bindir) ) ;
561+ let bin_rustdoc = bindir. join ( exe ( "rustdoc" , target_compiler. host ) ) ;
562+ let _ = fs:: remove_file ( & bin_rustdoc) ;
563+ bin_rustdoc
564+ } ;
565+
566+ // If CI rustc is enabled and we haven't modified the rustdoc sources,
567+ // use the precompiled rustdoc from CI rustc's sysroot to speed up bootstrapping.
568+ if builder. download_rustc ( )
569+ && target_compiler. stage > 0
570+ && builder. rust_info ( ) . is_managed_git_subrepository ( )
571+ {
572+ let commit = get_closest_merge_base_commit (
573+ Some ( & builder. config . src ) ,
574+ & builder. config . git_config ( ) ,
575+ & builder. config . stage0_metadata . config . git_merge_commit_email ,
576+ & [ ] ,
577+ )
578+ . unwrap ( ) ;
579+
580+ let librustdoc_src = builder. config . src . join ( "src/librustdoc" ) ;
581+ let rustdoc_src = builder. config . src . join ( "src/tools/rustdoc" ) ;
582+ let has_changes = !t ! ( git( Some ( & builder. config. src) )
583+ . args( [ "diff-index" , "--quiet" , & commit] )
584+ . arg( "--" )
585+ . arg( librustdoc_src)
586+ . arg( rustdoc_src)
587+ . command
588+ . status( ) )
589+ . success ( ) ;
590+
591+ if !has_changes {
592+ let precompiled_rustdoc = builder
593+ . config
594+ . ci_rustc_dir ( )
595+ . join ( "bin" )
596+ . join ( exe ( "rustdoc" , target_compiler. host ) ) ;
597+
598+ let bin_rustdoc = bin_rustdoc ( ) ;
599+ builder. copy_link ( & precompiled_rustdoc, & bin_rustdoc) ;
600+ return bin_rustdoc;
601+ }
602+ }
603+
556604 let build_compiler = if builder. download_rustc ( ) && target_compiler. stage == 1 {
557605 // We already have the stage 1 compiler, we don't need to cut the stage.
558606 builder. compiler ( target_compiler. stage , builder. config . build )
@@ -613,11 +661,7 @@ impl Step for Rustdoc {
613661
614662 // don't create a stage0-sysroot/bin directory.
615663 if target_compiler. stage > 0 {
616- let sysroot = builder. sysroot ( target_compiler) ;
617- let bindir = sysroot. join ( "bin" ) ;
618- t ! ( fs:: create_dir_all( & bindir) ) ;
619- let bin_rustdoc = bindir. join ( exe ( "rustdoc" , target_compiler. host ) ) ;
620- let _ = fs:: remove_file ( & bin_rustdoc) ;
664+ let bin_rustdoc = bin_rustdoc ( ) ;
621665 builder. copy_link ( & tool_rustdoc, & bin_rustdoc) ;
622666 bin_rustdoc
623667 } else {
0 commit comments