@@ -290,13 +290,41 @@ impl Client {
290
290
///
291
291
/// On platforms other than Unix and Windows this panics.
292
292
pub fn configure ( & self , cmd : & mut Command ) {
293
+ cmd. env ( "CARGO_MAKEFLAGS" , & self . mflags_env ( ) ) ;
294
+ self . inner . configure ( cmd) ;
295
+ }
296
+
297
+ /// Configures a child process to have access to this client's jobserver as
298
+ /// well.
299
+ ///
300
+ /// This function is required to be called to ensure that a jobserver is
301
+ /// properly inherited to a child process. If this function is *not* called
302
+ /// then this `Client` will not be accessible in the child process. In other
303
+ /// words, if not called, then `Client::from_env` will return `None` in the
304
+ /// child process (or the equivalent of `Child::from_env` that `make` uses).
305
+ ///
306
+ /// ## Platform-specific behavior
307
+ ///
308
+ /// On Unix and Windows this will clobber the `CARGO_MAKEFLAGS`,
309
+ /// `MAKEFLAGS` and `MFLAGS` environment variables for the child process,
310
+ /// and on Unix this will also allow the two file descriptors for
311
+ /// this client to be inherited to the child.
312
+ ///
313
+ /// On platforms other than Unix and Windows this panics.
314
+ pub fn configure_make ( & self , cmd : & mut Command ) {
315
+ let value = self . mflags_env ( ) ;
316
+ cmd. env ( "CARGO_MAKEFLAGS" , & value) ;
317
+ cmd. env ( "MAKEFLAGS" , & value) ;
318
+ cmd. env ( "MFLAGS" , & value) ;
319
+ self . inner . configure ( cmd) ;
320
+ }
321
+
322
+ fn mflags_env ( & self ) -> String {
293
323
let arg = self . inner . string_arg ( ) ;
294
324
// Older implementations of make use `--jobserver-fds` and newer
295
325
// implementations use `--jobserver-auth`, pass both to try to catch
296
326
// both implementations.
297
- let value = format ! ( "-j --jobserver-fds={0} --jobserver-auth={0}" , arg) ;
298
- cmd. env ( "CARGO_MAKEFLAGS" , & value) ;
299
- self . inner . configure ( cmd) ;
327
+ format ! ( "-j --jobserver-fds={0} --jobserver-auth={0}" , arg)
300
328
}
301
329
302
330
/// Converts this `Client` into a helper thread to deal with a blocking
0 commit comments