@@ -19,6 +19,7 @@ pub struct Build {
1919 debug : Option < bool > ,
2020}
2121
22+ #[ derive( Clone , Debug ) ]
2223pub struct Artifacts {
2324 include_dir : PathBuf ,
2425 lib_dir : PathBuf ,
@@ -67,7 +68,7 @@ impl Build {
6768 self
6869 }
6970
70- pub fn build ( & mut self , version : Version ) -> Artifacts {
71+ pub fn build ( & self , version : Version ) -> Artifacts {
7172 let target = & self . target . as_ref ( ) . expect ( "TARGET is not set" ) [ ..] ;
7273 let out_dir = self . out_dir . as_ref ( ) . expect ( "OUT_DIR is not set" ) ;
7374 let manifest_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
@@ -79,7 +80,19 @@ impl Build {
7980 }
8081
8182 let mut config = cc:: Build :: new ( ) ;
82- config. warnings ( false ) . cargo_metadata ( false ) ;
83+ config. warnings ( false ) . cargo_metadata ( false ) . target ( target) ;
84+
85+ match & self . host {
86+ Some ( host) => {
87+ config. host ( host) ;
88+ }
89+ // Host will be taken from the environment variable
90+ None if env:: var ( "HOST" ) . is_ok ( ) => { }
91+ None => {
92+ // If called outside of build script, set default host
93+ config. host ( target) ;
94+ }
95+ }
8396
8497 match target {
8598 _ if target. contains ( "linux" ) => {
@@ -141,17 +154,22 @@ impl Build {
141154 config. define ( "LUA_UCID" , None ) ;
142155 }
143156
144- if self . debug . unwrap_or ( cfg ! ( debug_assertions) ) {
157+ let debug = self . debug . unwrap_or ( cfg ! ( debug_assertions) ) ;
158+ if debug {
145159 config. define ( "LUA_USE_APICHECK" , None ) ;
146160 config. debug ( true ) ;
147161 }
148162
149- if let Some ( host) = & self . host {
150- config. host ( host) ;
151- }
152-
153- if let Some ( opt_level) = & self . opt_level {
154- config. opt_level_str ( opt_level) ;
163+ match & self . opt_level {
164+ Some ( opt_level) => {
165+ config. opt_level_str ( opt_level) ;
166+ }
167+ // Opt level will be taken from the environment variable
168+ None if env:: var ( "OPT_LEVEL" ) . is_ok ( ) => { }
169+ None => {
170+ // If called outside of build script, set default opt level
171+ config. opt_level ( if debug { 0 } else { 2 } ) ;
172+ }
155173 }
156174
157175 config
0 commit comments