1
1
use crate :: {
2
- app:: PackageFilters ,
2
+ app:: { BenchTargetFilters , PackageFilters } ,
3
3
helpers:: { clear_dir, get_codspeed_target_dir} ,
4
4
measurement_mode:: MeasurementMode ,
5
5
prelude:: * ,
@@ -8,6 +8,7 @@ use cargo_metadata::{camino::Utf8PathBuf, Message, Metadata, TargetKind};
8
8
use std:: process:: { exit, Command , Stdio } ;
9
9
10
10
struct BuildOptions < ' a > {
11
+ bench_target_filters : BenchTargetFilters ,
11
12
package_filters : PackageFilters ,
12
13
features : & ' a Option < Vec < String > > ,
13
14
profile : & ' a str ,
@@ -20,6 +21,16 @@ struct BuiltBench {
20
21
executable_path : Utf8PathBuf ,
21
22
}
22
23
24
+ pub struct BuildConfig {
25
+ pub package_filters : PackageFilters ,
26
+ pub bench_target_filters : BenchTargetFilters ,
27
+ pub features : Option < Vec < String > > ,
28
+ pub profile : String ,
29
+ pub quiet : bool ,
30
+ pub measurement_mode : MeasurementMode ,
31
+ pub passthrough_flags : Vec < String > ,
32
+ }
33
+
23
34
impl BuildOptions < ' _ > {
24
35
/// Builds the benchmarks by invoking cargo
25
36
/// Returns a list of built benchmarks, with path to associated executables
@@ -167,7 +178,15 @@ impl BuildOptions<'_> {
167
178
/// This command explicitly ignores the `self.benches`: all benches are built
168
179
fn build_command ( & self , measurement_mode : MeasurementMode ) -> Command {
169
180
let mut cargo = Command :: new ( "cargo" ) ;
170
- cargo. args ( [ "build" , "--benches" ] ) ;
181
+ cargo. arg ( "build" ) ;
182
+
183
+ if let Some ( bench_target_filters) = & self . bench_target_filters . bench {
184
+ for bench_target_filter in bench_target_filters {
185
+ cargo. args ( [ "--bench" , bench_target_filter] ) ;
186
+ }
187
+ } else {
188
+ cargo. args ( [ "--benches" ] ) ;
189
+ }
171
190
172
191
self . add_rust_flags ( & mut cargo, measurement_mode) ;
173
192
@@ -205,22 +224,15 @@ impl PackageFilters {
205
224
}
206
225
}
207
226
208
- pub fn build_benches (
209
- metadata : & Metadata ,
210
- package_filters : PackageFilters ,
211
- features : Option < Vec < String > > ,
212
- profile : String ,
213
- quiet : bool ,
214
- measurement_mode : MeasurementMode ,
215
- passthrough_flags : Vec < String > ,
216
- ) -> Result < ( ) > {
227
+ pub fn build_benches ( metadata : & Metadata , config : BuildConfig ) -> Result < ( ) > {
217
228
let built_benches = BuildOptions {
218
- package_filters,
219
- features : & features,
220
- profile : & profile,
221
- passthrough_flags : & passthrough_flags,
229
+ bench_target_filters : config. bench_target_filters ,
230
+ package_filters : config. package_filters ,
231
+ features : & config. features ,
232
+ profile : & config. profile ,
233
+ passthrough_flags : & config. passthrough_flags ,
222
234
}
223
- . build ( metadata, quiet, measurement_mode) ?;
235
+ . build ( metadata, config . quiet , config . measurement_mode ) ?;
224
236
225
237
if built_benches. is_empty ( ) {
226
238
bail ! (
@@ -229,7 +241,7 @@ pub fn build_benches(
229
241
) ;
230
242
}
231
243
232
- let codspeed_target_dir = get_codspeed_target_dir ( metadata, measurement_mode) ;
244
+ let codspeed_target_dir = get_codspeed_target_dir ( metadata, config . measurement_mode ) ;
233
245
let built_bench_count = built_benches. len ( ) ;
234
246
235
247
// Create and clear packages codspeed target directories
0 commit comments