1+ use crate :: runtime_group_step_name;
12use crate :: toolchain:: Toolchain ;
23use anyhow:: Context ;
34use benchlib:: benchmark:: passes_filter;
@@ -90,6 +91,12 @@ pub enum CargoIsolationMode {
9091 Isolated ,
9192}
9293
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+
93100/// Find all runtime benchmark crates in `benchmark_dir` and compile them.
94101/// We assume that each binary defines a benchmark suite using `benchlib`.
95102/// 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(
98105 toolchain : & Toolchain ,
99106 benchmark_dir : & Path ,
100107 isolation_mode : CargoIsolationMode ,
101- ) -> anyhow:: Result < BenchmarkSuite > {
108+ ) -> anyhow:: Result < BenchmarkSuiteCompilation > {
102109 let benchmark_crates = get_runtime_benchmark_groups ( benchmark_dir) ?;
103110
104111 let temp_dir: Option < TempDir > = match isolation_mode {
@@ -120,6 +127,7 @@ pub fn prepare_runtime_benchmark_suite(
120127 println ! ( "Compiling {group_count} runtime benchmark groups" ) ;
121128
122129 let mut groups = Vec :: new ( ) ;
130+ let mut failed_to_compile = HashMap :: new ( ) ;
123131 for ( index, benchmark_crate) in benchmark_crates. into_iter ( ) . enumerate ( ) {
124132 println ! (
125133 "Compiling {:<22} ({}/{group_count})" ,
@@ -129,25 +137,41 @@ pub fn prepare_runtime_benchmark_suite(
129137
130138 let target_dir = temp_dir. as_ref ( ) . map ( |d| d. path ( ) ) ;
131139
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)
133141 . with_context ( || {
134142 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+ }
141162 }
142163
143164 groups. sort_unstable_by ( |a, b| a. binary . cmp ( & b. binary ) ) ;
144165 log:: debug!( "Found binaries: {:?}" , groups) ;
145166
146167 check_duplicates ( & groups) ?;
147168
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,
151175 } )
152176}
153177
@@ -181,6 +205,7 @@ fn parse_benchmark_group(
181205 let mut group: Option < BenchmarkGroup > = None ;
182206
183207 let stream = BufReader :: new ( cargo_process. stdout . take ( ) . unwrap ( ) ) ;
208+ let mut messages = String :: new ( ) ;
184209 for message in Message :: parse_stream ( stream) {
185210 let message = message?;
186211 match message {
@@ -210,25 +235,28 @@ fn parse_benchmark_group(
210235 }
211236 }
212237 }
213- Message :: TextLine ( line) => println ! ( "{}" , line) ,
238+ Message :: TextLine ( line) => {
239+ println ! ( "{line}" )
240+ }
214241 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}" ) ;
216245 }
217246 _ => { }
218247 }
219248 }
220249
221- let group = group. ok_or_else ( || {
222- anyhow:: anyhow!( "Runtime benchmark group `{group_name}` has not produced any binary" )
223- } ) ?;
224-
225250 let output = cargo_process. wait ( ) ?;
226251 if !output. success ( ) {
227252 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 ) ,
230255 ) )
231256 } else {
257+ let group = group. ok_or_else ( || {
258+ anyhow:: anyhow!( "Runtime benchmark group `{group_name}` has not produced any binary" )
259+ } ) ?;
232260 Ok ( group)
233261 }
234262}
@@ -246,7 +274,7 @@ fn start_cargo_build(
246274 . arg ( "build" )
247275 . arg ( "--release" )
248276 . arg ( "--message-format" )
249- . arg ( "json-diagnostic-rendered-ansi " )
277+ . arg ( "json-diagnostic-short " )
250278 . current_dir ( benchmark_dir)
251279 . stdin ( Stdio :: null ( ) )
252280 . stdout ( Stdio :: piped ( ) )
0 commit comments