Re: [PATCH 20/23] kbuild: rust: parallelise rustc front end

From: Björn Baron

Date: Wed Sep 09 2026 - 06:31:26 EST


On Tuesday, September 8th, 2026 at 22:59, Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> wrote:

> Use the -Zthreads option to have rustc perform builds in parallel. This has
> been available since rust 1.84 (rust-lang/rust#132282), and the kernel
> requires rust 1.85 or above.
>
> [..]
>
> Generated output was confirmed byte-for-byte identical.

There are still several known reproducibility issues for the parallel
frontend[1] and at least until fairly recently there were also deadlock
issues and incorrect errors[2], so I would not recommend enabling it without
an explicit request from the user. Perhaps even only allow it on nightly
rustc for now, then you don't need to check which of the two spellings of
the flag is supported.

By the way, currently backend parallelism is entirely disabled due to the
usage of --emit obj (which forces -Ccodegen-units=1). For -O2/3 builds
enabling backend parallelism may have a bigger impact than frontend
parallelism. And it would make incremental compilation for rustc a lot more
effective as editing a single function would no longer need to codegen all
functions in a crate again, only those inside the same codegen unit.
Getting it working would require using --emit link to produce rlibs and
then linking those rlibs in the place of the raw object files. Rlibs are
just static libraries containing some extra rustc specific info that will
be ignored by the linker (no guarantees about this, but there are no
guarantees --emit obj can be linked without missing symbols either and I
don't know of any reason why we would change it right now. It would hurt
compile times due to needing to repackage all rlibs before rustc runs
linking.). I tried implementing this a couple of years ago, but back then
if I recall correctly either binutils ar or llvm-ar was unable to produce a
thin archive referencing members of another archive like Kbuild expects to
do. I'm not familiar enough with Kbuild to know how to skip the thin
archive production.

Link: https://github.com/rust-lang/rust/issues/?q=is%3Aissue%20state%3Aopen%20label%3AA-parallel-compiler [1]
Link: https://github.com/rust-lang/rust/issues/?q=is%3Aissue%20state%3Aclosed%20label%3AA-parallel-compiler [2]