-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support inheriting jobserver fd for external subcommands #10511
Conversation
r? @ehuss (rust-highfive has picked a reviewer for you, use r? to override) |
As a side note, I found that cargo doesn't respect |
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
So I've encountered a very similar situation with I try to use If the descriptors are closed, they later may be reopened by something unrelated, which will ICE rustc or cargo because they will still attempt to read/write something jobserver-like from those descriptors. (That's what happen in my build environment at least.) Maybe cargo needs some kind of explicit option to avoid closing jobserver descriptors in such cases. UPD: The workaround is to not use |
@petrochenkov, thanks for sharhing the interesting case. I feel like |
☔ The latest upstream changes (presumably #9892) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #10934) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry for the long delay. I think this makes sense. There's a tiny risk that it might interfere with some existing tools or workflows, but I think on balance it is the right behavior. @bors r+ |
☀️ Test successful - checks-actions |
8 commits in 4ed54cecce3ce9ab6ff058781f4c8a500ee6b8b5..646e9a0b9ea8354cc409d05f10e8dc752c5de78e 2022-08-27 18:41:39 +0000 to 2022-09-02 14:29:28 +0000 - Support inheriting jobserver fd for external subcommands (rust-lang/cargo#10511) - refactor(cli): Lazy load config (rust-lang/cargo#11029) - chore: Don't show genned docs in ripgrep (rust-lang/cargo#11040) - Document private items for Cargo and publish under contributor guide (rust-lang/cargo#11019) - Add names to CI jobs (rust-lang/cargo#11039) - Rework test error handling (rust-lang/cargo#11028) - Very slight `cargo add` documentation improvements (rust-lang/cargo#11033) - Update compiling requirements. (rust-lang/cargo#11030)
Update cargo 8 commits in 4ed54cecce3ce9ab6ff058781f4c8a500ee6b8b5..646e9a0b9ea8354cc409d05f10e8dc752c5de78e 2022-08-27 18:41:39 +0000 to 2022-09-02 14:29:28 +0000 - Support inheriting jobserver fd for external subcommands (rust-lang/cargo#10511) - refactor(cli): Lazy load config (rust-lang/cargo#11029) - chore: Don't show genned docs in ripgrep (rust-lang/cargo#11040) - Document private items for Cargo and publish under contributor guide (rust-lang/cargo#11019) - Add names to CI jobs (rust-lang/cargo#11039) - Rework test error handling (rust-lang/cargo#11028) - Very slight `cargo add` documentation improvements (rust-lang/cargo#11033) - Update compiling requirements. (rust-lang/cargo#11030)
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 rate. * Creating a jobsever driver with the new FIFO named pipe style is not yet supported as `[email protected]`. Once we can create a named pipe based jobserver, it will be less risky and inheritance by default can be implemented.
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.
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.
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 provides such an ability to the general `target.<...>.runner`, which affects `cargo test`, `cargo bench`, and `cargo run`. 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.
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 provides such an ability to the general `target.<...>.runner`, which affects `cargo test`, `cargo bench`, and `cargo run`. 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.
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 provides such an ability to the general `target.<...>.runner`, which affects `cargo test`, `cargo bench`, and `cargo run`. 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.
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 provides such an ability to the general `target.<...>.runner`, which affects `cargo test`, `cargo bench`, and `cargo run`. 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.
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 provides such an ability to the general `target.<...>.runner`, which affects `cargo test`, `cargo bench`, and `cargo run`. 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.
This was done in <rust-lang#10511>.
This was done in <rust-lang#10511>.
This was done in <rust-lang#10511>.
What does this PR try to resolve?
If cargo detects the existence of a jobserver, cargo should pass the
jobserver down to the external subcommand. Here are the reasons:
job is under control. However, before this commit, external
subcommands cannnot benefit from the global view of the jobserver.
cargo-clippy
as an external subcommand migth also love to respectthe jobserver protocol.
interally (cargo-fuzz, cargo-tarpaulin, etc.)
Fixes #10477
zulip stream
How should we test and review this PR?
A new test
jobserver::external_subcommand_inherits_jobserver
is added.You can also execute cargo-clippy from
make -j2
to test the behaviour(I usually run
procs -w rustc
to observe the amount of rustc invocations):Caveats
Job without special prefix
+
might still be considered as a sub-makeand would inherit the jobserver, though I don't see it as an issue.
According to GNU Make Manual "13.1.1 POSIX Jobserver Interaction",
if
--jobserver-auth
option is available inMAKEFLAGS
but the filedescriptors are closed, it means that the calling
make
didn't considerour tool awas a recursive
make
invocation. I make an assumption thatif those fds are still open, we are happy to use those jobserver tokens.