@@ -16,7 +16,7 @@ pub use self::{
1616
1717use anyhow:: { bail, Error , Result } ;
1818use clap:: { Parser , ValueEnum } ;
19- use std:: { fmt as stdfmt, path:: PathBuf , str:: FromStr } ;
19+ use std:: { fmt as stdfmt, ops :: Deref , path:: PathBuf , str:: FromStr } ;
2020
2121#[ derive( Copy , Clone , Debug , Eq , PartialEq , ValueEnum ) ]
2222pub enum Sanitizer {
@@ -51,6 +51,17 @@ pub enum BuildMode {
5151
5252#[ derive( Clone , Debug , Eq , PartialEq , Parser ) ]
5353pub struct BuildOptions {
54+ #[ command( flatten) ]
55+ pub fuzz_dir_wrapper : FuzzDirWrapper ,
56+
57+ /// Build all packages in the workspace
58+ #[ arg( long) ]
59+ pub workspace : bool ,
60+
61+ /// Package to build (see `cargo help pkgid`)
62+ #[ arg( short = 'p' , long = "package" ) ]
63+ pub packages : Vec < String > ,
64+
5465 /// Build artifacts in development mode, without optimizations
5566 #[ arg( short = 'D' , long, conflicts_with = "release" ) ]
5667 pub dev : bool ,
@@ -209,6 +220,16 @@ pub struct BuildOptions {
209220
210221impl stdfmt:: Display for BuildOptions {
211222 fn fmt ( & self , f : & mut stdfmt:: Formatter ) -> stdfmt:: Result {
223+ self . fuzz_dir_wrapper . fmt ( f) ?;
224+
225+ if self . workspace {
226+ write ! ( f, " --workspace" ) ?;
227+ }
228+
229+ for pkg in & self . packages {
230+ write ! ( f, " --package {}" , pkg) ?;
231+ }
232+
212233 if self . dev {
213234 write ! ( f, " -D" ) ?;
214235 }
@@ -270,10 +291,36 @@ pub struct FuzzDirWrapper {
270291 pub fuzz_dir : Option < PathBuf > ,
271292}
272293
294+ #[ derive( Debug , Clone ) ]
295+ pub struct ManifestPath ( PathBuf ) ;
296+
297+ impl ManifestPath {
298+ pub fn new ( path_buf : PathBuf ) -> Self {
299+ Self ( path_buf)
300+ }
301+ }
302+
303+ impl Deref for ManifestPath {
304+ type Target = PathBuf ;
305+
306+ fn deref ( & self ) -> & Self :: Target {
307+ & self . 0
308+ }
309+ }
310+
311+ impl FuzzDirWrapper {
312+ pub fn get_manifest_path ( & self ) -> Option < ManifestPath > {
313+ if let Some ( ref fuzz_dir) = self . fuzz_dir {
314+ return Some ( ManifestPath ( fuzz_dir. join ( "Cargo.toml" ) ) ) ;
315+ }
316+ None
317+ }
318+ }
319+
273320impl stdfmt:: Display for FuzzDirWrapper {
274321 fn fmt ( & self , f : & mut stdfmt:: Formatter ) -> stdfmt:: Result {
275322 if let Some ( ref elem) = self . fuzz_dir {
276- write ! ( f, " --fuzz-dir= {}" , elem. display( ) ) ?;
323+ write ! ( f, " --fuzz-dir {}" , elem. display( ) ) ?;
277324 }
278325
279326 Ok ( ( ) )
@@ -305,6 +352,9 @@ mod test {
305352 #[ test]
306353 fn display_build_options ( ) {
307354 let default_opts = BuildOptions {
355+ fuzz_dir_wrapper : FuzzDirWrapper { fuzz_dir : None } ,
356+ workspace : false ,
357+ packages : Vec :: new ( ) ,
308358 dev : false ,
309359 release : false ,
310360 debug_assertions : false ,
@@ -377,7 +427,29 @@ mod test {
377427 } ,
378428 BuildOptions {
379429 coverage: false ,
380- ..default_opts
430+ ..default_opts. clone( )
431+ } ,
432+ BuildOptions {
433+ workspace: false ,
434+ ..default_opts. clone( )
435+ } ,
436+ BuildOptions {
437+ packages: vec![ String :: from( "pkg1" ) ] ,
438+ ..default_opts. clone( )
439+ } ,
440+ BuildOptions {
441+ packages: vec![ String :: from( "pkg1" ) , String :: from( "pkg2" ) ] ,
442+ ..default_opts. clone( )
443+ } ,
444+ BuildOptions {
445+ workspace: true ,
446+ packages: vec![ String :: from( "pkg1" ) ] ,
447+ ..default_opts. clone( )
448+ } ,
449+ BuildOptions {
450+ workspace: true ,
451+ packages: vec![ String :: from( "pkg1" ) , String :: from( "pkg2" ) ] ,
452+ ..default_opts. clone( )
381453 } ,
382454 ] ;
383455
0 commit comments