Last compiling step only uses 1 CPU

When nearing the last step of compiling a Rust project, Rust uses 1 CPU. Up until then, it uses all available CPUs. I think it's linking all the different libraries together to build the final executable.

Here's an example program I was struggling with today: GitHub - rustic-rs/rustic: rustic - fast, encrypted, and deduplicated backups powered by Rust

Why can't this be done using all CPUs? It's very slow on my machine.

By default, Rust uses the linker provided by the platform, so it does not control how that process proceeds. Depending on your OS, there may be a faster third-party linker that you can use.

4 Likes

In particular, mold as a linker and sccache as a general compilation cache can substantially improve things, but I'm not sure if mold will work on macOS and it certainly won't work on Windows.