@@ -71,29 +71,33 @@ impl Step for ToolBuild {
71
71
///
72
72
/// This will build the specified tool with the specified `host` compiler in
73
73
/// `stage` into the normal cargo output directory.
74
- fn run ( self , builder : & Builder < ' _ > ) -> PathBuf {
75
- let compiler = self . compiler ;
76
- let target = self . target ;
77
- let mut tool = self . tool ;
78
- let path = self . path ;
79
-
74
+ fn run ( mut self , builder : & Builder < ' _ > ) -> PathBuf {
80
75
match self . mode {
81
76
Mode :: ToolRustc => {
82
- builder. ensure ( compile:: Std :: new ( compiler, compiler. host ) ) ;
83
- builder. ensure ( compile:: Rustc :: new ( compiler, target) ) ;
77
+ assert ! (
78
+ self . compiler. stage > 0 ,
79
+ "stage0 isn't supported for `Mode::ToolRustc` programs"
80
+ ) ;
81
+ // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
82
+ // we'd have stageN/bin/rustc and stageN/bin/$tool_name be effectively different stage
83
+ // compilers, which isn't what we want.
84
+ //
85
+ // Compiler tools should be linked in the same way as the compiler it's paired with,
86
+ // so it must be built with the previous stage compiler.
87
+ self . compiler . stage -= 1
84
88
}
85
- Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( compiler, target) ) ,
86
- Mode :: ToolBootstrap => { } // uses downloaded stage0 compiler libs
89
+ Mode :: ToolStd => builder. ensure ( compile:: Std :: new ( self . compiler , self . target ) ) ,
90
+ Mode :: ToolBootstrap => { }
87
91
_ => panic ! ( "unexpected Mode for tool build" ) ,
88
92
}
89
93
90
94
let mut cargo = prepare_tool_cargo (
91
95
builder,
92
- compiler,
96
+ self . compiler ,
93
97
self . mode ,
94
- target,
98
+ self . target ,
95
99
Kind :: Build ,
96
- path,
100
+ self . path ,
97
101
self . source_type ,
98
102
& self . extra_features ,
99
103
) ;
@@ -114,7 +118,7 @@ impl Step for ToolBuild {
114
118
let build_success = compile:: stream_cargo ( builder, cargo, vec ! [ ] , & mut |_| { } ) ;
115
119
116
120
builder. save_toolstate (
117
- tool,
121
+ self . tool ,
118
122
if build_success { ToolState :: TestFail } else { ToolState :: BuildFail } ,
119
123
) ;
120
124
@@ -124,10 +128,10 @@ impl Step for ToolBuild {
124
128
// HACK(#82501): on Windows, the tools directory gets added to PATH when running tests, and
125
129
// compiletest confuses HTML tidy with the in-tree tidy. Name the in-tree tidy something
126
130
// different so the problem doesn't come up.
127
- if tool == "tidy" {
128
- tool = "rust-tidy" ;
131
+ if self . tool == "tidy" {
132
+ self . tool = "rust-tidy" ;
129
133
}
130
- copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , tool)
134
+ copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , self . tool )
131
135
}
132
136
}
133
137
}
@@ -679,9 +683,9 @@ impl Step for Rustdoc {
679
683
) ;
680
684
cargo. into_cmd ( ) . run ( builder) ;
681
685
682
- // Cargo adds a number of paths to the dylib search path on windows, which results in
683
- // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
684
- // rustdoc a different name.
686
+ // Cargo adds a number of paths to the dylib search path on windows, which results in
687
+ // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
688
+ // rustdoc a different name.
685
689
let tool_rustdoc = builder
686
690
. cargo_out ( build_compiler, Mode :: ToolRustc , target)
687
691
. join ( exe ( "rustdoc_tool_binary" , target_compiler. host ) ) ;
@@ -1107,7 +1111,7 @@ fn run_tool_build_step(
1107
1111
path : & ' static str ,
1108
1112
add_bins_to_sysroot : Option < & [ & str ] > ,
1109
1113
) -> PathBuf {
1110
- let tool = builder. ensure ( ToolBuild {
1114
+ let bin_source = builder. ensure ( ToolBuild {
1111
1115
compiler,
1112
1116
target,
1113
1117
tool : tool_name,
@@ -1126,18 +1130,15 @@ fn run_tool_build_step(
1126
1130
let bindir = builder. sysroot ( compiler) . join ( "bin" ) ;
1127
1131
t ! ( fs:: create_dir_all( & bindir) ) ;
1128
1132
1129
- let tools_out = builder. cargo_out ( compiler, Mode :: ToolRustc , target) ;
1130
-
1131
1133
for add_bin in add_bins_to_sysroot {
1132
- let bin_source = tools_out. join ( exe ( add_bin, target) ) ;
1133
1134
let bin_destination = bindir. join ( exe ( add_bin, compiler. host ) ) ;
1134
1135
builder. copy_link ( & bin_source, & bin_destination) ;
1135
1136
}
1136
1137
1137
1138
// Return a path into the bin dir.
1138
1139
bindir. join ( exe ( tool_name, compiler. host ) )
1139
1140
} else {
1140
- tool
1141
+ bin_source
1141
1142
}
1142
1143
}
1143
1144
0 commit comments