@@ -3,19 +3,32 @@ use crate::{
3
3
prelude:: * ,
4
4
} ;
5
5
6
- use std:: fs:: create_dir_all;
6
+ use std:: { collections :: BTreeSet , fs:: create_dir_all, rc :: Rc } ;
7
7
8
8
use cargo:: {
9
- core:: { Package , Workspace } ,
9
+ core:: { FeatureValue , Package , Workspace } ,
10
10
ops:: { CompileFilter , CompileOptions , Packages } ,
11
- util:: command_prelude:: CompileMode ,
11
+ util:: { command_prelude:: CompileMode , interning :: InternedString } ,
12
12
Config ,
13
13
} ;
14
14
use termcolor:: Color ;
15
15
16
- fn get_compile_options ( config : & Config , package : & Package , bench : & str ) -> Result < CompileOptions > {
16
+ fn get_compile_options (
17
+ config : & Config ,
18
+ features : & Option < Vec < String > > ,
19
+ package : & Package ,
20
+ bench : & str ,
21
+ ) -> Result < CompileOptions > {
17
22
let mut compile_opts = CompileOptions :: new ( config, CompileMode :: Build ) ?;
18
23
compile_opts. spec = Packages :: Packages ( vec ! [ package. name( ) . to_string( ) ] ) ;
24
+ if let Some ( features) = features {
25
+ compile_opts. cli_features . features = Rc :: new (
26
+ features
27
+ . iter ( )
28
+ . map ( |s| FeatureValue :: Feature ( InternedString :: new ( s. as_str ( ) ) ) )
29
+ . collect :: < BTreeSet < FeatureValue > > ( ) ,
30
+ ) ;
31
+ }
19
32
compile_opts. build_config . requested_profile = "release" . into ( ) ;
20
33
compile_opts. filter = CompileFilter :: from_raw_arguments (
21
34
false ,
@@ -36,6 +49,7 @@ pub fn build_benches(
36
49
ws : & Workspace ,
37
50
selected_benches : Option < Vec < String > > ,
38
51
package_name : Option < String > ,
52
+ features : Option < Vec < String > > ,
39
53
) -> Result < ( ) > {
40
54
let package = match package_name. as_ref ( ) {
41
55
Some ( package_name) => ws
@@ -82,7 +96,7 @@ pub fn build_benches(
82
96
ws. config ( )
83
97
. shell ( )
84
98
. status_with_color ( "Building" , bench. name ( ) , Color :: Yellow ) ?;
85
- let compile_opts = get_compile_options ( config, package, bench. name ( ) ) ?;
99
+ let compile_opts = get_compile_options ( config, & features , package, bench. name ( ) ) ?;
86
100
let result = cargo:: ops:: compile ( ws, & compile_opts) ?;
87
101
let built_targets = result
88
102
. tests
0 commit comments