Skip to content

Commit 2a10478

Browse files
committed
Add alternative linker to the build performance guide
1 parent a390202 commit 2a10478

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/doc/src/guide/build-performance.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,31 @@ Trade-offs:
107107
[parallel-frontend-blog]: https://blog.rust-lang.org/2023/11/09/parallel-rustc/
108108
[parallel-frontend-issue]: https://github.com/rust-lang/rust/issues/113349
109109
[build.rustflags]: ../reference/config.md#buildrustflags
110+
111+
### Use an alternative linker
112+
113+
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.
114+
115+
Recommendation:
116+
117+
- Install an alternative linker, for example [LLD](https://lld.llvm.org/), [mold](https://github.com/rui314/mold) or [wild](https://github.com/davidlattimore/wild)
118+
- 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`:
119+
120+
```toml
121+
# LLD
122+
[target.'cfg(target_os = "linux")']
123+
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
124+
125+
# mold, if you have GCC 12+
126+
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
127+
128+
# mold, otherwise
129+
linker = "clang"
130+
rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"]
131+
```
132+
133+
> Note that since Rust `1.90.0`, the `x86_64-unknown-linux-gnu` target already defaults to the LLD linker.
134+
135+
Trade-offs:
136+
- ✅ Faster link times
137+
- ❌ Might not support all use-cases, in particular if you depend on C or C++ dependencies

0 commit comments

Comments
 (0)