@@ -271,6 +271,21 @@ pub struct Compiler {
271271 )
272272 ) ]
273273 pub unstable : Vec < String > ,
274+
275+ // The following options are primarily used by `cargo miden build` to pass through
276+ // familiar Cargo options. They are hidden from `midenc --help` output.
277+ /// Build in release mode (used by cargo miden build)
278+ #[ cfg_attr( feature = "std" , arg( long, hide = true , default_value_t = false ) ) ]
279+ pub release : bool ,
280+ /// Path to Cargo.toml (used by cargo miden build)
281+ #[ cfg_attr( feature = "std" , arg( long, value_name = "PATH" , hide = true ) ) ]
282+ pub manifest_path : Option < PathBuf > ,
283+ /// Build all packages in the workspace (used by cargo miden build)
284+ #[ cfg_attr( feature = "std" , arg( long, hide = true , default_value_t = false ) ) ]
285+ pub workspace : bool ,
286+ /// Package(s) to build (used by cargo miden build)
287+ #[ cfg_attr( feature = "std" , arg( long, value_name = "SPEC" , hide = true ) ) ]
288+ pub package : Vec < String > ,
274289}
275290
276291#[ derive( Default , Debug , Clone ) ]
@@ -435,6 +450,28 @@ NOTE: When specifying these options, strip the leading '--'",
435450}
436451
437452impl Compiler {
453+ /// Parse compiler options from command-line arguments.
454+ ///
455+ /// Returns the parsed options or an error if parsing failed.
456+ /// This is used by `cargo miden build` to parse all arguments into `Compiler`
457+ /// options before selectively forwarding them to `cargo build` and `midenc`.
458+ #[ cfg( feature = "std" ) ]
459+ pub fn try_parse_from < I , T > ( iter : I ) -> Result < Self , clap:: Error >
460+ where
461+ I : IntoIterator < Item = T > ,
462+ T : Into < OsString > + Clone ,
463+ {
464+ let argv = [ OsString :: from ( "midenc" ) ]
465+ . into_iter ( )
466+ . chain ( iter. into_iter ( ) . map ( |arg| arg. into ( ) ) ) ;
467+ let command = <Self as clap:: CommandFactory >:: command ( ) ;
468+ let command = midenc_session:: flags:: register_flags ( command) ;
469+ let mut matches = command. try_get_matches_from ( argv) ?;
470+
471+ <Self as clap:: FromArgMatches >:: from_arg_matches_mut ( & mut matches)
472+ . map_err ( format_error :: < Self > )
473+ }
474+
438475 /// Construct a [Compiler] programatically
439476 #[ cfg( feature = "std" ) ]
440477 pub fn new_session < I , A , S > ( inputs : I , emitter : Option < Arc < dyn Emitter > > , argv : A ) -> Session
0 commit comments