11use std:: env;
2- use std:: ffi:: { OsStr , OsString } ;
2+ use std:: ffi:: OsStr ;
33use std:: io:: BufReader ;
44use std:: path:: PathBuf ;
55use std:: process:: { Command , Stdio } ;
66
77use anyhow:: anyhow;
88use cargo_metadata:: { Message , Version } ;
9+ use clap:: Args ;
910use embuild:: utils:: CmdError ;
10- use structopt:: StructOpt ;
1111
1212#[ derive( Debug , thiserror:: Error ) ]
1313pub enum BuildError {
@@ -27,12 +27,16 @@ pub enum BuildError {
2727 CargoMsgError ( #[ source] std:: io:: Error ) ,
2828}
2929
30- #[ derive( Debug , StructOpt ) ]
30+ #[ derive( Debug , Args ) ]
31+ #[ clap( help_heading = "BUILD OPTIONS" ) ]
3132pub struct BuildOpts {
32- #[ structopt ( flatten) ]
33+ #[ clap ( flatten) ]
3334 manifest : clap_cargo:: Manifest ,
34- #[ structopt ( flatten) ]
35+ #[ clap ( flatten) ]
3536 features : clap_cargo:: Features ,
37+ /// Build with release profile
38+ #[ clap( long) ]
39+ release : bool ,
3640}
3741
3842pub struct BuildInfo {
@@ -65,19 +69,22 @@ pub fn run(opts: BuildOpts) -> Result<BuildInfo, BuildError> {
6569 drop ( meta) ;
6670
6771 // Build the crate
68- let mut cmd = Command :: new ( env:: var_os ( "CARGO" ) . unwrap_or_else ( || OsString :: from ( "cargo" ) ) ) ;
72+ let mut cmd = Command :: new ( env:: var_os ( "CARGO" ) . unwrap_or_else ( || "cargo" . into ( ) ) ) ;
6973 cmd. args ( & [ "build" , "--message-format=json-diagnostic-rendered-ansi" ] )
7074 . stdout ( Stdio :: piped ( ) )
7175 . stderr ( Stdio :: inherit ( ) ) ;
7276 if let Some ( ref manifest) = opts. manifest . manifest_path {
73- cmd. args ( & [ OsStr :: new ( "--manifest-path" ) , manifest. as_os_str ( ) ] ) ;
77+ cmd. args ( [ OsStr :: new ( "--manifest-path" ) , manifest. as_os_str ( ) ] ) ;
7478 }
7579 if opts. features . all_features {
7680 cmd. arg ( "--all-features" ) ;
7781 }
7882 if opts. features . no_default_features {
7983 cmd. arg ( "--no-default-features" ) ;
8084 }
85+ if opts. release {
86+ cmd. arg ( "--release" ) ;
87+ }
8188 if !opts. features . features . is_empty ( ) {
8289 cmd. args ( & [ "--features" , & opts. features . features . join ( "," ) ] ) ;
8390 }
0 commit comments