1111//! Cargo build utilities for building and analyzing Rust libraries.
1212
1313use cargo_metadata:: Message ;
14- use log:: debug;
14+ use log:: { debug, trace } ;
1515use std:: {
1616 io:: { self , BufReader } ,
1717 path:: { Path , PathBuf } ,
@@ -31,9 +31,13 @@ pub struct CargoBuildResult {
3131impl CargoBuilder {
3232 /// Create a new CargoBuilder instance
3333 pub fn new ( ) -> Self {
34+ let mut args = vec ! [ "build" , "--lib" , "--message-format" , "json" ] ;
35+ if !cfg ! ( debug_assertions) {
36+ args. push ( "--release" ) ;
37+ }
3438 let mut command = Command :: new ( env ! ( "CARGO" ) ) ;
3539 command
36- . args ( [ "build" , "--lib" , "--message-format" , "json" ] )
40+ . args ( & args )
3741 . stdin ( Stdio :: null ( ) )
3842 . stdout ( Stdio :: piped ( ) )
3943 . stderr ( Stdio :: null ( ) ) ;
@@ -54,6 +58,14 @@ impl CargoBuilder {
5458
5559 /// Execute the cargo build command and return the result
5660 pub fn build ( & mut self ) -> io:: Result < CargoBuildResult > {
61+ debug ! ( command: % = {
62+ let program = self . command. get_program( ) ;
63+ let args = self . command. get_args( ) ;
64+ let mut command = vec![ program] ;
65+ command. extend( args) ;
66+ command. join( " " . as_ref( ) ) . to_string_lossy( ) . to_string( )
67+ } ; "run cargo build command" ) ;
68+
5769 let mut child = self . command . spawn ( ) ?;
5870 let stdout = child
5971 . stdout
@@ -62,7 +74,7 @@ impl CargoBuilder {
6274 let reader = BufReader :: new ( stdout) ;
6375 let mut messages = Vec :: new ( ) ;
6476 for message in cargo_metadata:: Message :: parse_stream ( reader) {
65- debug ! ( message: ?; "cargo build message" ) ;
77+ trace ! ( message: ?; "cargo build message" ) ;
6678 let message = message?;
6779 messages. push ( message) ;
6880 }
0 commit comments