From d24396001138c44e12db52e09d17fbfb255b89aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 20 Sep 2025 14:14:41 +0200 Subject: [PATCH 1/2] Add alternative linker to the build performance guide --- src/doc/src/guide/build-performance.md | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/doc/src/guide/build-performance.md b/src/doc/src/guide/build-performance.md index c321ee8a4f4..028c34c26ef 100644 --- a/src/doc/src/guide/build-performance.md +++ b/src/doc/src/guide/build-performance.md @@ -89,3 +89,31 @@ Trade-offs: [parallel-frontend-blog]: https://blog.rust-lang.org/2023/11/09/parallel-rustc/ [parallel-frontend-issue]: https://github.com/rust-lang/rust/issues/113349 [build.rustflags]: ../reference/config.md#buildrustflags + +### Use an alternative linker + +Most targets default to using the system linker, which might not be the most performant option. You can try an alternative linker to see if it improves build performance. + +Recommendation: + +- Install an alternative linker, for example [LLD](https://lld.llvm.org/), [mold](https://github.com/rui314/mold) or [wild](https://github.com/davidlattimore/wild) +- Configure the Rust compiler to use a different linker. The configuration depends on the used linker and operating system. For Linux and the LLD or mold linker, you can add to your `.cargo/config.toml`: + +```toml +# LLD +[target.'cfg(target_os = "linux")'] +rustflags = ["-C", "link-arg=-fuse-ld=lld"] + +# mold, if you have GCC 12+ +rustflags = ["-C", "link-arg=-fuse-ld=mold"] + +# mold, otherwise +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"] +``` + +> Note that since Rust `1.90.0`, the `x86_64-unknown-linux-gnu` target already defaults to the LLD linker. + +Trade-offs: +- ✅ Faster link times +- ❌ Might not support all use-cases, in particular if you depend on C or C++ dependencies From f0a5f75b57a62bb2133f4281cdd485fd862ff777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sun, 21 Sep 2025 10:13:09 +0200 Subject: [PATCH 2/2] Clarify code generation vs build times benefits --- src/doc/src/guide/build-performance.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/src/guide/build-performance.md b/src/doc/src/guide/build-performance.md index 028c34c26ef..864506f2d01 100644 --- a/src/doc/src/guide/build-performance.md +++ b/src/doc/src/guide/build-performance.md @@ -38,7 +38,7 @@ This will: - Provide an opt-in for when debugging via [`--profile debugging`](../reference/profiles.md#custom-profiles) Trade-offs: -- ✅ Faster build times +- ✅ Faster code generation (`cargo build`) - ✅ Faster link times - ✅ Smaller disk usage of the `target` directory - ❌ Requires a full rebuild to have a high-quality debugger experience @@ -83,7 +83,7 @@ rustflags = "-Zthreads=8" This [`rustflags`][build.rustflags] will enable the [parallel frontend][parallel-frontend-blog] of the Rust compiler, and tell it to use `n` threads. The value of `n` should be chosen according to the number of cores available on your system, although there are diminishing returns. We recommend using at most `8` threads. Trade-offs: -- ✅ Faster build times +- ✅ Faster build times (both `cargo check` and `cargo build`) - ❌ **Requires using nightly Rust and an [unstable Rust feature][parallel-frontend-issue]** [parallel-frontend-blog]: https://blog.rust-lang.org/2023/11/09/parallel-rustc/