1
+ use crate :: runtime_group_step_name;
1
2
use crate :: toolchain:: Toolchain ;
2
3
use anyhow:: Context ;
3
4
use benchlib:: benchmark:: passes_filter;
@@ -90,6 +91,12 @@ pub enum CargoIsolationMode {
90
91
Isolated ,
91
92
}
92
93
94
+ pub struct BenchmarkSuiteCompilation {
95
+ pub suite : BenchmarkSuite ,
96
+ // Maps benchmark group name to compilation error
97
+ pub failed_to_compile : HashMap < String , String > ,
98
+ }
99
+
93
100
/// Find all runtime benchmark crates in `benchmark_dir` and compile them.
94
101
/// We assume that each binary defines a benchmark suite using `benchlib`.
95
102
/// We then execute each benchmark suite with the `list-benchmarks` command to find out its
@@ -98,7 +105,7 @@ pub fn prepare_runtime_benchmark_suite(
98
105
toolchain : & Toolchain ,
99
106
benchmark_dir : & Path ,
100
107
isolation_mode : CargoIsolationMode ,
101
- ) -> anyhow:: Result < BenchmarkSuite > {
108
+ ) -> anyhow:: Result < BenchmarkSuiteCompilation > {
102
109
let benchmark_crates = get_runtime_benchmark_groups ( benchmark_dir) ?;
103
110
104
111
let temp_dir: Option < TempDir > = match isolation_mode {
@@ -120,6 +127,7 @@ pub fn prepare_runtime_benchmark_suite(
120
127
println ! ( "Compiling {group_count} runtime benchmark groups" ) ;
121
128
122
129
let mut groups = Vec :: new ( ) ;
130
+ let mut failed_to_compile = HashMap :: new ( ) ;
123
131
for ( index, benchmark_crate) in benchmark_crates. into_iter ( ) . enumerate ( ) {
124
132
println ! (
125
133
"Compiling {:<22} ({}/{group_count})" ,
@@ -129,25 +137,41 @@ pub fn prepare_runtime_benchmark_suite(
129
137
130
138
let target_dir = temp_dir. as_ref ( ) . map ( |d| d. path ( ) ) ;
131
139
132
- let cargo_process = start_cargo_build ( toolchain, & benchmark_crate. path , target_dir)
140
+ let result = start_cargo_build ( toolchain, & benchmark_crate. path , target_dir)
133
141
. with_context ( || {
134
142
anyhow:: anyhow!( "Cannot start compilation of {}" , benchmark_crate. name)
135
- } ) ?;
136
- let group =
137
- parse_benchmark_group ( cargo_process, & benchmark_crate. name ) . with_context ( || {
138
- anyhow:: anyhow!( "Cannot compile runtime benchmark {}" , benchmark_crate. name)
139
- } ) ?;
140
- groups. push ( group) ;
143
+ } )
144
+ . and_then ( |process| {
145
+ parse_benchmark_group ( process, & benchmark_crate. name ) . with_context ( || {
146
+ anyhow:: anyhow!( "Cannot compile runtime benchmark {}" , benchmark_crate. name)
147
+ } )
148
+ } ) ;
149
+ match result {
150
+ Ok ( group) => groups. push ( group) ,
151
+ Err ( error) => {
152
+ log:: error!(
153
+ "Cannot compile runtime benchmark group `{}`" ,
154
+ benchmark_crate. name
155
+ ) ;
156
+ failed_to_compile. insert (
157
+ runtime_group_step_name ( & benchmark_crate. name ) ,
158
+ format ! ( "{error:?}" ) ,
159
+ ) ;
160
+ }
161
+ }
141
162
}
142
163
143
164
groups. sort_unstable_by ( |a, b| a. binary . cmp ( & b. binary ) ) ;
144
165
log:: debug!( "Found binaries: {:?}" , groups) ;
145
166
146
167
check_duplicates ( & groups) ?;
147
168
148
- Ok ( BenchmarkSuite {
149
- groups,
150
- _tmp_artifacts_dir : temp_dir,
169
+ Ok ( BenchmarkSuiteCompilation {
170
+ suite : BenchmarkSuite {
171
+ groups,
172
+ _tmp_artifacts_dir : temp_dir,
173
+ } ,
174
+ failed_to_compile,
151
175
} )
152
176
}
153
177
@@ -181,6 +205,7 @@ fn parse_benchmark_group(
181
205
let mut group: Option < BenchmarkGroup > = None ;
182
206
183
207
let stream = BufReader :: new ( cargo_process. stdout . take ( ) . unwrap ( ) ) ;
208
+ let mut messages = String :: new ( ) ;
184
209
for message in Message :: parse_stream ( stream) {
185
210
let message = message?;
186
211
match message {
@@ -210,25 +235,28 @@ fn parse_benchmark_group(
210
235
}
211
236
}
212
237
}
213
- Message :: TextLine ( line) => println ! ( "{}" , line) ,
238
+ Message :: TextLine ( line) => {
239
+ println ! ( "{line}" )
240
+ }
214
241
Message :: CompilerMessage ( msg) => {
215
- print ! ( "{}" , msg. message. rendered. unwrap_or( msg. message. message) )
242
+ let message = msg. message . rendered . unwrap_or ( msg. message . message ) ;
243
+ messages. push_str ( & message) ;
244
+ print ! ( "{message}" ) ;
216
245
}
217
246
_ => { }
218
247
}
219
248
}
220
249
221
- let group = group. ok_or_else ( || {
222
- anyhow:: anyhow!( "Runtime benchmark group `{group_name}` has not produced any binary" )
223
- } ) ?;
224
-
225
250
let output = cargo_process. wait ( ) ?;
226
251
if !output. success ( ) {
227
252
Err ( anyhow:: anyhow!(
228
- "Failed to compile runtime benchmark, exit code {}" ,
229
- output. code( ) . unwrap_or( 1 )
253
+ "Failed to compile runtime benchmark, exit code {}\n {messages} " ,
254
+ output. code( ) . unwrap_or( 1 ) ,
230
255
) )
231
256
} else {
257
+ let group = group. ok_or_else ( || {
258
+ anyhow:: anyhow!( "Runtime benchmark group `{group_name}` has not produced any binary" )
259
+ } ) ?;
232
260
Ok ( group)
233
261
}
234
262
}
@@ -246,7 +274,7 @@ fn start_cargo_build(
246
274
. arg ( "build" )
247
275
. arg ( "--release" )
248
276
. arg ( "--message-format" )
249
- . arg ( "json-diagnostic-rendered-ansi " )
277
+ . arg ( "json-diagnostic-short " )
250
278
. current_dir ( benchmark_dir)
251
279
. stdin ( Stdio :: null ( ) )
252
280
. stdout ( Stdio :: piped ( ) )
0 commit comments