Skip to content

Commit ffc0149

Browse files
committed
Disable Make jobserver support on OSX
On OSX, CMake (via libuv) spawns child processes, including make, via the Apple-specific `posix_spawn` attribute `POSIX_SPAWN_CLOEXEC_DEFAULT`. This blocks make from accessing all non-stdio file descriptors from the parent process, including those of the jobserver. Because make was getting passed jobserver information via MAKEFLAGS but was unable to access the jobserver, it prints an error like the following and proceeds to run a single-threaded build: ``` make: warning: jobserver unavailable: using -j1. Add '+' to parent make rule. ``` As a workaround, disable jobserver support on OSX so that cmake-rs instead passes `--parallel $NUM_JOBS` to CMake, allowing for a faster multi-threaded build.
1 parent 94da9de commit ffc0149

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,16 +837,18 @@ impl Config {
837837
let mut use_jobserver = false;
838838
if fs::metadata(build.join("Makefile")).is_ok() {
839839
match env::var_os("CARGO_MAKEFLAGS") {
840-
// Only do this on non-windows and non-bsd
840+
// Only do this on non-windows, non-bsd, and non-osx
841841
// On Windows, we could be invoking make instead of
842842
// mingw32-make which doesn't work with our jobserver
843843
// bsdmake also does not work with our job server
844+
// On OSX, CMake blocks propagation of the jobserver's file descriptors to make
844845
Some(ref makeflags)
845846
if !(cfg!(windows)
846847
|| cfg!(target_os = "openbsd")
847848
|| cfg!(target_os = "netbsd")
848849
|| cfg!(target_os = "freebsd")
849-
|| cfg!(target_os = "dragonfly")) =>
850+
|| cfg!(target_os = "dragonfly")
851+
|| cfg!(target_os = "macos")) =>
850852
{
851853
use_jobserver = true;
852854
cmd.env("MAKEFLAGS", makeflags);

0 commit comments

Comments
 (0)