@@ -75,29 +75,33 @@ impl Step for ToolBuild {
75
75
///
76
76
/// This will build the specified tool with the specified `host` compiler in
77
77
/// `stage` into the normal cargo output directory.
78
- fn run ( self , builder : & Builder < ' _ > ) -> PathBuf {
79
- let compiler = self . compiler ;
80
- let target = self . target ;
81
- let mut tool = self . tool ;
82
- let path = self . path ;
83
-
78
+ fn run ( mut self , builder : & Builder < ' _ > ) -> PathBuf {
84
79
match self . mode {
85
80
Mode :: ToolRustc => {
86
- builder. ensure ( compile:: Std :: new ( compiler, compiler. host ) ) ;
87
- builder. ensure ( compile:: Rustc :: new ( compiler, target) ) ;
81
+ assert ! (
82
+ self . compiler. stage > 0 ,
83
+ "stage0 isn't supported for `Mode::ToolRustc` programs"
84
+ ) ;
85
+ // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
86
+ // we'd have stageN/bin/rustc and stageN/bin/$tool_name be effectively different stage
87
+ // compilers, which isn't what we want.
88
+ //
89
+ // Compiler tools should be linked in the same way as the compiler it's paired with,
90
+ // so it must be built with the previous stage compiler.
91
+ self . compiler . stage -= 1
88
92
}
89
- Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( compiler, target) ) ,
90
- Mode :: ToolBootstrap => { } // uses downloaded stage0 compiler libs
93
+ Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( self . compiler , self . target ) ) ,
94
+ Mode :: ToolBootstrap => { }
91
95
_ => panic ! ( "unexpected Mode for tool build" ) ,
92
96
}
93
97
94
98
let mut cargo = prepare_tool_cargo (
95
99
builder,
96
- compiler,
100
+ self . compiler ,
97
101
self . mode ,
98
- target,
102
+ self . target ,
99
103
Kind :: Build ,
100
- path,
104
+ self . path ,
101
105
self . source_type ,
102
106
& self . extra_features ,
103
107
) ;
@@ -118,7 +122,7 @@ impl Step for ToolBuild {
118
122
let build_success = compile:: stream_cargo ( builder, cargo, vec ! [ ] , & mut |_| { } ) ;
119
123
120
124
builder. save_toolstate (
121
- tool,
125
+ self . tool ,
122
126
if build_success { ToolState :: TestFail } else { ToolState :: BuildFail } ,
123
127
) ;
124
128
@@ -128,10 +132,10 @@ impl Step for ToolBuild {
128
132
// HACK(#82501): on Windows, the tools directory gets added to PATH when running tests, and
129
133
// compiletest confuses HTML tidy with the in-tree tidy. Name the in-tree tidy something
130
134
// different so the problem doesn't come up.
131
- if tool == "tidy" {
132
- tool = "rust-tidy" ;
135
+ if self . tool == "tidy" {
136
+ self . tool = "rust-tidy" ;
133
137
}
134
- copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , tool)
138
+ copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , self . tool )
135
139
}
136
140
}
137
141
}
@@ -693,9 +697,9 @@ impl Step for Rustdoc {
693
697
) ;
694
698
cargo. into_cmd ( ) . run ( builder) ;
695
699
696
- // Cargo adds a number of paths to the dylib search path on windows, which results in
697
- // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
698
- // rustdoc a different name.
700
+ // Cargo adds a number of paths to the dylib search path on windows, which results in
701
+ // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
702
+ // rustdoc a different name.
699
703
let tool_rustdoc = builder
700
704
. cargo_out ( build_compiler, Mode :: ToolRustc , target)
701
705
. join ( exe ( "rustdoc_tool_binary" , target_compiler. host ) ) ;
@@ -1134,7 +1138,7 @@ fn run_tool_build_step(
1134
1138
path : & ' static str ,
1135
1139
add_bins_to_sysroot : Option < & [ & str ] > ,
1136
1140
) -> PathBuf {
1137
- let tool = builder. ensure ( ToolBuild {
1141
+ let bin_source = builder. ensure ( ToolBuild {
1138
1142
compiler,
1139
1143
target,
1140
1144
tool : tool_name,
@@ -1153,18 +1157,15 @@ fn run_tool_build_step(
1153
1157
let bindir = builder. sysroot ( compiler) . join ( "bin" ) ;
1154
1158
t ! ( fs:: create_dir_all( & bindir) ) ;
1155
1159
1156
- let tools_out = builder. cargo_out ( compiler, Mode :: ToolRustc , target) ;
1157
-
1158
1160
for add_bin in add_bins_to_sysroot {
1159
- let bin_source = tools_out. join ( exe ( add_bin, target) ) ;
1160
1161
let bin_destination = bindir. join ( exe ( add_bin, compiler. host ) ) ;
1161
1162
builder. copy_link ( & bin_source, & bin_destination) ;
1162
1163
}
1163
1164
1164
1165
// Return a path into the bin dir.
1165
1166
bindir. join ( exe ( tool_name, compiler. host ) )
1166
1167
} else {
1167
- tool
1168
+ bin_source
1168
1169
}
1169
1170
}
1170
1171
0 commit comments