@@ -3,19 +3,32 @@ use crate::{
33 prelude:: * ,
44} ;
55
6- use std:: fs:: create_dir_all;
6+ use std:: { collections :: BTreeSet , fs:: create_dir_all, rc :: Rc } ;
77
88use cargo:: {
9- core:: { Package , Workspace } ,
9+ core:: { FeatureValue , Package , Workspace } ,
1010 ops:: { CompileFilter , CompileOptions , Packages } ,
11- util:: command_prelude:: CompileMode ,
11+ util:: { command_prelude:: CompileMode , interning :: InternedString } ,
1212 Config ,
1313} ;
1414use termcolor:: Color ;
1515
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 > {
1722 let mut compile_opts = CompileOptions :: new ( config, CompileMode :: Build ) ?;
1823 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+ }
1932 compile_opts. build_config . requested_profile = "release" . into ( ) ;
2033 compile_opts. filter = CompileFilter :: from_raw_arguments (
2134 false ,
@@ -36,6 +49,7 @@ pub fn build_benches(
3649 ws : & Workspace ,
3750 selected_benches : Option < Vec < String > > ,
3851 package_name : Option < String > ,
52+ features : Option < Vec < String > > ,
3953) -> Result < ( ) > {
4054 let package = match package_name. as_ref ( ) {
4155 Some ( package_name) => ws
@@ -82,7 +96,7 @@ pub fn build_benches(
8296 ws. config ( )
8397 . shell ( )
8498 . 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 ( ) ) ?;
86100 let result = cargo:: ops:: compile ( ws, & compile_opts) ?;
87101 let built_targets = result
88102 . tests
0 commit comments