Skip to content

Commit 5c5a9f7

Browse files
authored
Respect jobserver set by Cargo (#120)
Signed-off-by: Jakub Beránek <[email protected]>
1 parent 19fffb1 commit 5c5a9f7

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

jemalloc-sys/build.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,32 +302,25 @@ fn main() {
302302

303303
// Make:
304304
let make = make_cmd(&host);
305-
run(Command::new(make)
306-
.current_dir(&build_dir)
307-
.arg("-j")
308-
.arg(num_jobs.clone()));
305+
run(&mut make_command(make, &build_dir, &num_jobs));
309306

310307
// Skip watching this environment variables to avoid rebuild in CI.
311308
if env::var("JEMALLOC_SYS_RUN_JEMALLOC_TESTS").is_ok() {
312309
info!("Building and running jemalloc tests...");
310+
311+
let mut cmd = make_command(make, &build_dir, &num_jobs);
312+
313313
// Make tests:
314-
run(Command::new(make)
315-
.current_dir(&build_dir)
316-
.arg("-j")
317-
.arg(num_jobs.clone())
318-
.arg("tests"));
314+
run(cmd.arg("tests"));
319315

320316
// Run tests:
321317
run(Command::new(make).current_dir(&build_dir).arg("check"));
322318
}
323319

324320
// Make install:
325-
run(Command::new(make)
326-
.current_dir(&build_dir)
321+
run(make_command(make, &build_dir, &num_jobs)
327322
.arg("install_lib_static")
328-
.arg("install_include")
329-
.arg("-j")
330-
.arg(num_jobs));
323+
.arg("install_include"));
331324

332325
println!("cargo:root={}", out_dir.display());
333326

@@ -367,6 +360,23 @@ fn main() {
367360
}
368361
}
369362

363+
fn make_command(make_cmd: &str, build_dir: &Path, num_jobs: &str) -> Command {
364+
let mut cmd = Command::new(make_cmd);
365+
cmd.current_dir(build_dir);
366+
367+
if let Ok(makeflags) = std::env::var("CARGO_MAKEFLAGS") {
368+
let makeflags = if let Ok(orig_makeflags) = std::env::var("MAKEFLAGS") {
369+
format!("{orig_makeflags} {makeflags}")
370+
} else {
371+
makeflags
372+
};
373+
cmd.env("MAKEFLAGS", makeflags);
374+
} else {
375+
cmd.arg("-j").arg(num_jobs);
376+
}
377+
cmd
378+
}
379+
370380
fn run_and_log(cmd: &mut Command, log_file: &Path) {
371381
execute(cmd, || {
372382
run(Command::new("tail").arg("-n").arg("100").arg(log_file));

0 commit comments

Comments
 (0)