Skip to content

Tracking Issue for integration with --jobs options in rustc #17483

Description

@petrochenkov

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-jobserverArea: jobserver, concurrency, parallelismC-tracking-issueCategory: A tracking issue for something unstable.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions