@@ -307,32 +307,25 @@ fn main() {
307307
308308 // Make:
309309 let make = make_cmd ( & host) ;
310- run ( Command :: new ( make)
311- . current_dir ( & build_dir)
312- . arg ( "-j" )
313- . arg ( num_jobs. clone ( ) ) ) ;
310+ run ( & mut make_command ( make, & build_dir, & num_jobs) ) ;
314311
315312 // Skip watching this environment variables to avoid rebuild in CI.
316313 if env:: var ( "JEMALLOC_SYS_RUN_JEMALLOC_TESTS" ) . is_ok ( ) {
317314 info ! ( "Building and running jemalloc tests..." ) ;
315+
316+ let mut cmd = make_command ( make, & build_dir, & num_jobs) ;
317+
318318 // Make tests:
319- run ( Command :: new ( make)
320- . current_dir ( & build_dir)
321- . arg ( "-j" )
322- . arg ( num_jobs. clone ( ) )
323- . arg ( "tests" ) ) ;
319+ run ( cmd. arg ( "tests" ) ) ;
324320
325321 // Run tests:
326322 run ( Command :: new ( make) . current_dir ( & build_dir) . arg ( "check" ) ) ;
327323 }
328324
329325 // Make install:
330- run ( Command :: new ( make)
331- . current_dir ( & build_dir)
326+ run ( make_command ( make, & build_dir, & num_jobs)
332327 . arg ( "install_lib_static" )
333- . arg ( "install_include" )
334- . arg ( "-j" )
335- . arg ( num_jobs) ) ;
328+ . arg ( "install_include" ) ) ;
336329
337330 println ! ( "cargo:root={}" , out_dir. display( ) ) ;
338331
@@ -372,6 +365,23 @@ fn main() {
372365 }
373366}
374367
368+ fn make_command ( make_cmd : & str , build_dir : & Path , num_jobs : & str ) -> Command {
369+ let mut cmd = Command :: new ( make_cmd) ;
370+ cmd. current_dir ( build_dir) ;
371+
372+ if let Ok ( makeflags) = std:: env:: var ( "CARGO_MAKEFLAGS" ) {
373+ let makeflags = if let Ok ( orig_makeflags) = std:: env:: var ( "MAKEFLAGS" ) {
374+ format ! ( "{orig_makeflags} {makeflags}" )
375+ } else {
376+ makeflags
377+ } ;
378+ cmd. env ( "MAKEFLAGS" , makeflags) ;
379+ } else {
380+ cmd. arg ( "-j" ) . arg ( num_jobs) ;
381+ }
382+ cmd
383+ }
384+
375385fn run_and_log ( cmd : & mut Command , log_file : & Path ) {
376386 execute ( cmd, || {
377387 run ( Command :: new ( "tail" ) . arg ( "-n" ) . arg ( "100" ) . arg ( log_file) ) ;
0 commit comments