Skip to content

Commit 993a70b

Browse files
committed
feat(cargo-run): inherit jobserver from env
External subcommands are already able to inherit the jobserver from env since rust-lang#10511. However, users reported that they've expected `cargo run` to behave the same as external subcommands. A popular example "cargo-xtask" pattern is used as scripting to run arbitrary tasks. Users may want to invoke `cargo run` from Make and expect some parallelism. This PR tries to provide such an ability. Note that this PR doesn't create any jobserver client if there is no existing jobserver from the environment. Nor `-j`/`--jobs` would create a new client. Reasons for this decision: * There might be crates don't want the jobserver to pollute their file descriptors, although they might be rare * Creating a jobsever driver with the new FIFO named pipe style is not yet supported as of `[email protected]`. Once we can create a named pipe-based jobserver, it will be less risky and inheritance by default can be implemented.
1 parent 54c8fe8 commit 993a70b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/cargo/ops/cargo_run.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ pub fn run(
104104
process.display_env_vars();
105105
}
106106

107+
if let Some(client) = config.jobserver_from_env() {
108+
process.inherit_jobserver(client);
109+
}
110+
107111
config.shell().status("Running", process.to_string())?;
108112

109113
process.exec_replace()

tests/testsuite/jobserver.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,10 @@ all:
134134
)
135135
.build();
136136

137-
p.process(make).env("CARGO", cargo_exe()).arg("-j2")
138-
.with_status(2)
139-
.with_stderr_contains("[..]no jobserver from env[..]")
140-
.run();
137+
// jobserver can be inherited from env
138+
p.process(make).env("CARGO", cargo_exe()).arg("-j2").run();
141139

140+
// but not from `-j` flag
142141
p.cargo("run -j2")
143142
.with_status(101)
144143
.with_stderr_contains("[..]no jobserver from env[..]")

0 commit comments

Comments
 (0)