@@ -18,9 +18,14 @@ fn get_compile_options(
1818 features : & Option < Vec < String > > ,
1919 package : & Package ,
2020 benches : Vec < & str > ,
21+ is_root_package : bool ,
2122) -> Result < CompileOptions > {
2223 let mut compile_opts = CompileOptions :: new ( config, CompileMode :: Build ) ?;
23- compile_opts. spec = Packages :: Packages ( vec ! [ package. name( ) . to_string( ) ] ) ;
24+
25+ // if the package is not the root package, we need to specify the package to build
26+ if !is_root_package {
27+ compile_opts. spec = Packages :: Packages ( vec ! [ package. name( ) . to_string( ) ] ) ;
28+ }
2429 if let Some ( features) = features {
2530 compile_opts. cli_features . features = Rc :: new (
2631 features
@@ -51,14 +56,15 @@ pub fn build_benches(
5156 package_name : Option < String > ,
5257 features : Option < Vec < String > > ,
5358) -> Result < ( ) > {
59+ let is_root_package = package_name. is_none ( ) ;
5460 let package = match package_name. as_ref ( ) {
55- Some ( package_name) => ws
56- . members ( )
57- . find ( |p| p. name ( ) . to_string ( ) == * package_name)
58- . ok_or_else ( || anyhow ! ( "Package {} not found" , package_name) ) ?,
59- None => ws. current ( ) . map_err ( |_| anyhow ! ( "No package found. If working with a workspace please use the -p option to specify a member." ) ) ?,
60- } ;
61+ Some ( package_name) => ws. members ( )
62+ . find ( |p| p. name ( ) . to_string ( ) == * package_name)
63+ . ok_or_else ( || anyhow ! ( "Package {} not found" , package_name) ) ?
6164
65+ ,
66+ None => ws. current ( ) . map_err ( |_| anyhow ! ( "No package found. If working with a workspace please use the -p option to specify a member." ) ) ?
67+ } ;
6268 let all_benches = package
6369 . targets ( )
6470 . iter ( )
@@ -99,7 +105,8 @@ pub fn build_benches(
99105 ws. config ( )
100106 . shell ( )
101107 . status_with_color ( "Building" , benches_names_str. clone ( ) , Color :: Yellow ) ?;
102- let compile_opts = get_compile_options ( config, & features, package, benches_names) ?;
108+ let compile_opts =
109+ get_compile_options ( config, & features, package, benches_names, is_root_package) ?;
103110 let result = cargo:: ops:: compile ( ws, & compile_opts) ?;
104111 let built_benches = result
105112 . tests
0 commit comments