11
11
//! Cargo build utilities for building and analyzing Rust libraries.
12
12
13
13
use cargo_metadata:: Message ;
14
- use log:: debug;
14
+ use log:: { debug, trace } ;
15
15
use std:: {
16
16
io:: { self , BufReader } ,
17
17
path:: { Path , PathBuf } ,
@@ -31,9 +31,13 @@ pub struct CargoBuildResult {
31
31
impl CargoBuilder {
32
32
/// Create a new CargoBuilder instance
33
33
pub fn new ( ) -> Self {
34
+ let mut args = vec ! [ "build" , "--lib" , "--message-format" , "json" ] ;
35
+ if !cfg ! ( debug_assertions) {
36
+ args. push ( "--release" ) ;
37
+ }
34
38
let mut command = Command :: new ( env ! ( "CARGO" ) ) ;
35
39
command
36
- . args ( [ "build" , "--lib" , "--message-format" , "json" ] )
40
+ . args ( & args )
37
41
. stdin ( Stdio :: null ( ) )
38
42
. stdout ( Stdio :: piped ( ) )
39
43
. stderr ( Stdio :: null ( ) ) ;
@@ -54,6 +58,14 @@ impl CargoBuilder {
54
58
55
59
/// Execute the cargo build command and return the result
56
60
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
+
57
69
let mut child = self . command . spawn ( ) ?;
58
70
let stdout = child
59
71
. stdout
@@ -62,7 +74,7 @@ impl CargoBuilder {
62
74
let reader = BufReader :: new ( stdout) ;
63
75
let mut messages = Vec :: new ( ) ;
64
76
for message in cargo_metadata:: Message :: parse_stream ( reader) {
65
- debug ! ( message: ?; "cargo build message" ) ;
77
+ trace ! ( message: ?; "cargo build message" ) ;
66
78
let message = message?;
67
79
messages. push ( message) ;
68
80
}
0 commit comments