@@ -69,29 +69,33 @@ impl Step for ToolBuild {
69
69
///
70
70
/// This will build the specified tool with the specified `host` compiler in
71
71
/// `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 {
78
73
match self . mode {
79
74
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
82
86
}
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 => { }
85
89
_ => panic ! ( "unexpected Mode for tool build" ) ,
86
90
}
87
91
88
92
let mut cargo = prepare_tool_cargo (
89
93
builder,
90
- compiler,
94
+ self . compiler ,
91
95
self . mode ,
92
- target,
96
+ self . target ,
93
97
Kind :: Build ,
94
- path,
98
+ self . path ,
95
99
self . source_type ,
96
100
& self . extra_features ,
97
101
) ;
@@ -112,7 +116,7 @@ impl Step for ToolBuild {
112
116
let build_success = compile:: stream_cargo ( builder, cargo, vec ! [ ] , & mut |_| { } ) ;
113
117
114
118
builder. save_toolstate (
115
- tool,
119
+ self . tool ,
116
120
if build_success { ToolState :: TestFail } else { ToolState :: BuildFail } ,
117
121
) ;
118
122
@@ -122,10 +126,10 @@ impl Step for ToolBuild {
122
126
// HACK(#82501): on Windows, the tools directory gets added to PATH when running tests, and
123
127
// compiletest confuses HTML tidy with the in-tree tidy. Name the in-tree tidy something
124
128
// 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" ;
127
131
}
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 )
129
133
}
130
134
}
131
135
}
@@ -666,9 +670,9 @@ impl Step for Rustdoc {
666
670
) ;
667
671
cargo. into_cmd ( ) . run ( builder) ;
668
672
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.
672
676
let tool_rustdoc = builder
673
677
. cargo_out ( build_compiler, Mode :: ToolRustc , target)
674
678
. join ( exe ( "rustdoc_tool_binary" , target_compiler. host ) ) ;
@@ -1094,7 +1098,7 @@ fn run_tool_build_step(
1094
1098
path : & ' static str ,
1095
1099
add_bins_to_sysroot : Option < & [ & str ] > ,
1096
1100
) -> PathBuf {
1097
- let tool = builder. ensure ( ToolBuild {
1101
+ let bin_source = builder. ensure ( ToolBuild {
1098
1102
compiler,
1099
1103
target,
1100
1104
tool : tool_name,
@@ -1113,18 +1117,15 @@ fn run_tool_build_step(
1113
1117
let bindir = builder. sysroot ( compiler) . join ( "bin" ) ;
1114
1118
t ! ( fs:: create_dir_all( & bindir) ) ;
1115
1119
1116
- let tools_out = builder. cargo_out ( compiler, Mode :: ToolRustc , target) ;
1117
-
1118
1120
for add_bin in add_bins_to_sysroot {
1119
- let bin_source = tools_out. join ( exe ( add_bin, target) ) ;
1120
1121
let bin_destination = bindir. join ( exe ( add_bin, compiler. host ) ) ;
1121
1122
builder. copy_link ( & bin_source, & bin_destination) ;
1122
1123
}
1123
1124
1124
1125
// Return a path into the bin dir.
1125
1126
bindir. join ( exe ( tool_name, compiler. host ) )
1126
1127
} else {
1127
- tool
1128
+ bin_source
1128
1129
}
1129
1130
}
1130
1131
0 commit comments