Summary
Compiler MCP: rust-lang/compiler-team#1005
Documentation: https://doc.rust-lang.org/nightly/rustc/command-line-arguments.html#-j--jobs---jobs-frontend---jobs-backend---jobs-linker-limit-parallelism
rustc options
rustc now has a number of options to control parallelism - --jobs/-j for the total limit, and more specific options like --jobs-frontend for specific parts of the compiler.
The options are currently unstable, but the plan is to stabilize them as a part of compiler MCP 1005.
Documentation for the options can be found in here.
Even if cargo limits parallelism in rustc dynamically by passing a jobserver to it, it's still benefitial to limit it statically as well by passing the --jobs option, then rustc will know the maximum amount of jobs it will be able to use and account for it when e.g. creating thread pools. If the limit is 1 rustc will be able to perform even more optimizations.
What we expect cargo to do
When the options are stable
If cargo determines that it should use N jobs (from command line, or config file, or env vars, or the thread::available_parallelism default), it passes --jobs N to the compiler.
While the options are not yet stable
If cargo determines that it should use N jobs and detects a nightly compiler, it passes --jobs N -Zunstable-options to the compiler.
Something similar is already done for options like -Zembed-metadata.
When user wants to set frontend parallelism specifically
There are reasons to set --jobs-frontend to 1 even if the parallelism is set to a larger number in general, e.g. to get reproducible diagnostics, or to get reproducible binaries until the binary reproducibility bugs are fixed.
Ideally, cargo should support setting jobs-frontend = M in cargo configs, so that users don't have to pass it through RUSTFLAGS, and other tools like rust-analyzer could also use it consistently from the same source.
Same applies to jobs-backend and jobs-linker, but the motivation may be not so strong.
Unlike --jobs, which should always be passed, the fine grained options should be passed only if they are explicitly set in cargo config.
@Bryanskiy will provide an implementation for this if the direction is generally approved by the cargo team.
Unresolved Issues
No response
Future Extensions
If cargo uses N jobs, it can potentially pass some smaller number M to rustc, if it determines that the CPU is already busy enough with compiling other crates and will continue being busy for a while.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Summary
Compiler MCP: rust-lang/compiler-team#1005
Documentation: https://doc.rust-lang.org/nightly/rustc/command-line-arguments.html#-j--jobs---jobs-frontend---jobs-backend---jobs-linker-limit-parallelism
rustcoptionsrustc now has a number of options to control parallelism -
--jobs/-jfor the total limit, and more specific options like--jobs-frontendfor specific parts of the compiler.The options are currently unstable, but the plan is to stabilize them as a part of compiler MCP 1005.
Documentation for the options can be found in here.
Even if cargo limits parallelism in rustc dynamically by passing a jobserver to it, it's still benefitial to limit it statically as well by passing the
--jobsoption, then rustc will know the maximum amount of jobs it will be able to use and account for it when e.g. creating thread pools. If the limit is1rustc will be able to perform even more optimizations.What we expect cargo to do
When the options are stable
If cargo determines that it should use
Njobs (from command line, or config file, or env vars, or thethread::available_parallelismdefault), it passes--jobs Nto the compiler.While the options are not yet stable
If cargo determines that it should use
Njobs and detects a nightly compiler, it passes--jobs N -Zunstable-optionsto the compiler.Something similar is already done for options like
-Zembed-metadata.When user wants to set frontend parallelism specifically
There are reasons to set
--jobs-frontendto 1 even if the parallelism is set to a larger number in general, e.g. to get reproducible diagnostics, or to get reproducible binaries until the binary reproducibility bugs are fixed.Ideally, cargo should support setting
jobs-frontend = Min cargo configs, so that users don't have to pass it throughRUSTFLAGS, and other tools like rust-analyzer could also use it consistently from the same source.Same applies to
jobs-backendandjobs-linker, but the motivation may be not so strong.Unlike
--jobs, which should always be passed, the fine grained options should be passed only if they are explicitly set in cargo config.@Bryanskiy will provide an implementation for this if the direction is generally approved by the cargo team.
Unresolved Issues
No response
Future Extensions
If cargo uses
Njobs, it can potentially pass some smaller numberMto rustc, if it determines that the CPU is already busy enough with compiling other crates and will continue being busy for a while.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.