Skip to content

Commit 1c18e7e

Browse files
committed
Add section about using an alternative linker
1 parent 2d87627 commit 1c18e7e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ Trade-offs:
8989
[parallel-frontend-blog]: https://blog.rust-lang.org/2023/11/09/parallel-rustc/
9090
[parallel-frontend-issue]: https://github.com/rust-lang/rust/issues/113349
9191
[build.rustflags]: ../reference/config.md#buildrustflags
92+
93+
### Use an alternative linker
94+
95+
Consider: installing and configuring an alternative linker, like [LLD](https://lld.llvm.org/), [mold](https://github.com/rui314/mold) or [wild](https://github.com/davidlattimore/wild). For example, to configure mold on Linux, you can add to your `.cargo/config.toml`:
96+
97+
```toml
98+
[target.'cfg(target_os = "linux")']
99+
# mold, if you have GCC 12+
100+
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
101+
102+
# mold, otherwise
103+
linker = "clang"
104+
rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"]
105+
```
106+
107+
While dependencies may be built in parallel, linking all of your dependencies happens at once at the end of your build, which can make linking dominate your build times, especially for incremental rebuilds. Often, the linker Rust uses is already fairly fast and the gains from switching may not be worth it, but it is not always the case. For example, Linux targets besides `x86_64-unknown-linux-gnu` still use the Linux system linker which is quite slow (see [rust#39915](https://github.com/rust-lang/rust/issues/39915) for more details).
108+
109+
Trade-offs:
110+
- ✅ Faster link times
111+
- ❌ Might not support all use-cases, in particular if you depend on C or C++ dependencies
112+
92113
## Reducing built code
93114

94115
### Removing unused dependencies

0 commit comments

Comments
 (0)