11use crate :: {
2- app:: PackageFilters ,
2+ app:: { BenchTargetFilters , PackageFilters } ,
33 helpers:: { clear_dir, get_codspeed_target_dir} ,
44 measurement_mode:: MeasurementMode ,
55 prelude:: * ,
@@ -8,6 +8,7 @@ use cargo_metadata::{camino::Utf8PathBuf, Message, Metadata, TargetKind};
88use std:: process:: { exit, Command , Stdio } ;
99
1010struct BuildOptions < ' a > {
11+ bench_target_filters : BenchTargetFilters ,
1112 package_filters : PackageFilters ,
1213 features : & ' a Option < Vec < String > > ,
1314 profile : & ' a str ,
@@ -20,6 +21,16 @@ struct BuiltBench {
2021 executable_path : Utf8PathBuf ,
2122}
2223
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+
2334impl BuildOptions < ' _ > {
2435 /// Builds the benchmarks by invoking cargo
2536 /// Returns a list of built benchmarks, with path to associated executables
@@ -167,7 +178,15 @@ impl BuildOptions<'_> {
167178 /// This command explicitly ignores the `self.benches`: all benches are built
168179 fn build_command ( & self , measurement_mode : MeasurementMode ) -> Command {
169180 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+ }
171190
172191 self . add_rust_flags ( & mut cargo, measurement_mode) ;
173192
@@ -205,22 +224,15 @@ impl PackageFilters {
205224 }
206225}
207226
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 < ( ) > {
217228 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 ,
222234 }
223- . build ( metadata, quiet, measurement_mode) ?;
235+ . build ( metadata, config . quiet , config . measurement_mode ) ?;
224236
225237 if built_benches. is_empty ( ) {
226238 bail ! (
@@ -229,7 +241,7 @@ pub fn build_benches(
229241 ) ;
230242 }
231243
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 ) ;
233245 let built_bench_count = built_benches. len ( ) ;
234246
235247 // Create and clear packages codspeed target directories
0 commit comments