Skip to content

Commit

Permalink
Merge pull request #42 from NobodyXu/fix/configure-make
Browse files Browse the repository at this point in the history
Add `configure_make`: Set `MAKEFLAGS` & `MFLAGS`
  • Loading branch information
alexcrichton authored Jul 5, 2022
2 parents a66acbc + a55f5f2 commit 888d2d7
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,41 @@ impl Client {
///
/// On platforms other than Unix and Windows this panics.
pub fn configure(&self, cmd: &mut Command) {
cmd.env("CARGO_MAKEFLAGS", &self.mflags_env());
self.inner.configure(cmd);
}

/// Configures a child process to have access to this client's jobserver as
/// well.
///
/// This function is required to be called to ensure that a jobserver is
/// properly inherited to a child process. If this function is *not* called
/// then this `Client` will not be accessible in the child process. In other
/// words, if not called, then `Client::from_env` will return `None` in the
/// child process (or the equivalent of `Child::from_env` that `make` uses).
///
/// ## Platform-specific behavior
///
/// On Unix and Windows this will clobber the `CARGO_MAKEFLAGS`,
/// `MAKEFLAGS` and `MFLAGS` environment variables for the child process,
/// and on Unix this will also allow the two file descriptors for
/// this client to be inherited to the child.
///
/// On platforms other than Unix and Windows this panics.
pub fn configure_make(&self, cmd: &mut Command) {
let value = self.mflags_env();
cmd.env("CARGO_MAKEFLAGS", &value);
cmd.env("MAKEFLAGS", &value);
cmd.env("MFLAGS", &value);
self.inner.configure(cmd);
}

fn mflags_env(&self) -> String {
let arg = self.inner.string_arg();
// Older implementations of make use `--jobserver-fds` and newer
// implementations use `--jobserver-auth`, pass both to try to catch
// both implementations.
let value = format!("-j --jobserver-fds={0} --jobserver-auth={0}", arg);
cmd.env("CARGO_MAKEFLAGS", &value);
self.inner.configure(cmd);
format!("-j --jobserver-fds={0} --jobserver-auth={0}", arg)
}

/// Converts this `Client` into a helper thread to deal with a blocking
Expand Down

0 comments on commit 888d2d7

Please sign in to comment.