@@ -69,29 +69,33 @@ impl Step for ToolBuild {
6969 ///
7070 /// This will build the specified tool with the specified `host` compiler in
7171 /// `stage` into the normal cargo output directory.
72- fn run ( self , builder : & Builder < ' _ > ) -> PathBuf {
73- let compiler = self . compiler ;
74- let target = self . target ;
75- let mut tool = self . tool ;
76- let path = self . path ;
77-
72+ fn run ( mut self , builder : & Builder < ' _ > ) -> PathBuf {
7873 match self . mode {
7974 Mode :: ToolRustc => {
80- builder. ensure ( compile:: Std :: new ( compiler, compiler. host ) ) ;
81- builder. ensure ( compile:: Rustc :: new ( compiler, target) ) ;
75+ assert ! (
76+ self . compiler. stage > 0 ,
77+ "stage0 isn't supported for `Mode::ToolRustc` programs"
78+ ) ;
79+ // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
80+ // we'd have stageN/bin/rustc and stageN/bin/$tool_name be effectively different stage
81+ // compilers, which isn't what we want.
82+ //
83+ // Compiler tools should be linked in the same way as the compiler it's paired with,
84+ // so it must be built with the previous stage compiler.
85+ self . compiler . stage -= 1
8286 }
83- Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( compiler, target) ) ,
84- Mode :: ToolBootstrap => { } // uses downloaded stage0 compiler libs
87+ Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( self . compiler , self . target ) ) ,
88+ Mode :: ToolBootstrap => { }
8589 _ => panic ! ( "unexpected Mode for tool build" ) ,
8690 }
8791
8892 let mut cargo = prepare_tool_cargo (
8993 builder,
90- compiler,
94+ self . compiler ,
9195 self . mode ,
92- target,
96+ self . target ,
9397 Kind :: Build ,
94- path,
98+ self . path ,
9599 self . source_type ,
96100 & self . extra_features ,
97101 ) ;
@@ -112,7 +116,7 @@ impl Step for ToolBuild {
112116 let build_success = compile:: stream_cargo ( builder, cargo, vec ! [ ] , & mut |_| { } ) ;
113117
114118 builder. save_toolstate (
115- tool,
119+ self . tool ,
116120 if build_success { ToolState :: TestFail } else { ToolState :: BuildFail } ,
117121 ) ;
118122
@@ -122,10 +126,10 @@ impl Step for ToolBuild {
122126 // HACK(#82501): on Windows, the tools directory gets added to PATH when running tests, and
123127 // compiletest confuses HTML tidy with the in-tree tidy. Name the in-tree tidy something
124128 // different so the problem doesn't come up.
125- if tool == "tidy" {
126- tool = "rust-tidy" ;
129+ if self . tool == "tidy" {
130+ self . tool = "rust-tidy" ;
127131 }
128- copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , tool)
132+ copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , self . tool )
129133 }
130134 }
131135}
@@ -666,9 +670,9 @@ impl Step for Rustdoc {
666670 ) ;
667671 cargo. into_cmd ( ) . run ( builder) ;
668672
669- // Cargo adds a number of paths to the dylib search path on windows, which results in
670- // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
671- // rustdoc a different name.
673+ // Cargo adds a number of paths to the dylib search path on windows, which results in
674+ // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
675+ // rustdoc a different name.
672676 let tool_rustdoc = builder
673677 . cargo_out ( build_compiler, Mode :: ToolRustc , target)
674678 . join ( exe ( "rustdoc_tool_binary" , target_compiler. host ) ) ;
@@ -1094,7 +1098,7 @@ fn run_tool_build_step(
10941098 path : & ' static str ,
10951099 add_bins_to_sysroot : Option < & [ & str ] > ,
10961100) -> PathBuf {
1097- let tool = builder. ensure ( ToolBuild {
1101+ let bin_source = builder. ensure ( ToolBuild {
10981102 compiler,
10991103 target,
11001104 tool : tool_name,
@@ -1113,18 +1117,15 @@ fn run_tool_build_step(
11131117 let bindir = builder. sysroot ( compiler) . join ( "bin" ) ;
11141118 t ! ( fs:: create_dir_all( & bindir) ) ;
11151119
1116- let tools_out = builder. cargo_out ( compiler, Mode :: ToolRustc , target) ;
1117-
11181120 for add_bin in add_bins_to_sysroot {
1119- let bin_source = tools_out. join ( exe ( add_bin, target) ) ;
11201121 let bin_destination = bindir. join ( exe ( add_bin, compiler. host ) ) ;
11211122 builder. copy_link ( & bin_source, & bin_destination) ;
11221123 }
11231124
11241125 // Return a path into the bin dir.
11251126 bindir. join ( exe ( tool_name, compiler. host ) )
11261127 } else {
1127- tool
1128+ bin_source
11281129 }
11291130}
11301131
0 commit comments