Skip to content

Commit c1b90b9

Browse files
committed
Support inheriting jobserver fd for external subcommands
If cargo detects the existence of a jobserver, cargo should pass the jobserver down to the external subcommand. Here are the reasons: 1. The existence of jobserver implies the user "expects" the amount of job is under control. However, before this commit, external subcommands cannnot benefit from the global view of the jobserver. 2. `cargo-clippy` as an external subcommand migth also love to respect the jobserver protocol. 3. There are several well-known external subcommands calling "cargo" interally (cargo-fuzz, cargo-tarpaulin, etc.) Caveats: Job without special prefix `+` might still be considered as a sub-make and would inherit the jobserver, though I don't see it as an issue. According to GNU Make Manual "13.1.1 POSIX Jobserver Interaction" [^1], if `--jobserver-auth` option is available in `MAKEFLAGS` but the file descriptors are closed, it means that the calling `make` didn't consider our tool awas a recursive `make` invocation. I make an assumption that if those fds are still open, we are happy to use those jobserver tokens. [^1]: https://www.gnu.org/software/make/manual/make.html#POSIX-Jobserver
1 parent b099d39 commit c1b90b9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/bin/cargo/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
174174
};
175175

176176
let cargo_exe = config.cargo_exe()?;
177-
let err = match ProcessBuilder::new(&command)
178-
.env(cargo::CARGO_ENV, cargo_exe)
179-
.args(args)
180-
.exec_replace()
181-
{
177+
let mut cmd = ProcessBuilder::new(&command);
178+
cmd.env(cargo::CARGO_ENV, cargo_exe).args(args);
179+
if let Some(client) = config.jobserver_from_env() {
180+
cmd.inherit_jobserver(client);
181+
}
182+
let err = match cmd.exec_replace() {
182183
Ok(()) => return Ok(()),
183184
Err(e) => e,
184185
};

0 commit comments

Comments
 (0)