Skip to content

Commit dd77c44

Browse files
bgwNeosoulink
authored andcommitted
Switch from ld (the default linker) to using lld for GNU Linux targets (vercel#8166)
**What's wrong with `ld`?** It's very slow and uses a lot of memory. **Why `lld`?** It's fast, mature, and well-supported. Meta and Google use it for all their linking workloads. We're already using it for macos and x86-64 Windows. There is [ongoing work to make it the default for rustc](rust-lang/rust#71515), and it already is default on a few platforms. **Why not `mold`?** Mold is generally faster, but the margin is slim enough for our workloads that it doesn't really matter. Mold only recently got support for LTO, doesn't support v0 rust symbol demanging, doesn't support BOLT (though we don't use that yet), etc. Mold is maturing quickly, but `lld` still seems like the "safer" choice.
1 parent bbd89b9 commit dd77c44

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

.cargo/config.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ rustdocflags = ["-Znormalize-docs"]
1515
[target.x86_64-pc-windows-msvc]
1616
linker = "rust-lld"
1717

18-
[target.aarch64-apple-darwin]
18+
[target.'cfg(target_os = "macos")']
1919
linker = "rust-lld"
2020

21-
[target.x86_64-apple-darwin]
22-
linker = "rust-lld"
21+
[target.'cfg(all(target_os = "linux", target_env = "gnu"))']
22+
rustflags = [
23+
"--cfg",
24+
"tokio_unstable",
25+
"-Zshare-generics=y",
26+
"-Zthreads=8",
27+
"-Csymbol-mangling-version=v0",
28+
"-Clink-arg=-fuse-ld=lld",
29+
]
2330

2431
[alias]
2532
xtask = "run --package xtask --"

.github/actions/setup-rust/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ runs:
3434
# we want more specific settings
3535
cache: false
3636

37+
- name: "Install LLD (LLVM Linker) for Linux"
38+
if: runner.os == 'Linux'
39+
shell: bash
40+
run: sudo apt-get -y update && sudo apt-get install -y lld
41+
3742
- name: "Set Windows default host to MinGW"
3843
if: ${{ inputs.windows == 'true' }}
3944
shell: bash

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Thanks for your interest in contributing to Turbo!
2929
- [Rust](https://www.rust-lang.org/tools/install)
3030
- [cargo-groups](https://github.com/nicholaslyang/cargo-groups) (used to group crates into Turborepo-specific ones and Turbopack-specific ones)
3131

32+
### Linux Dependencies
33+
34+
- LLD (LLVM Linker), as it's not installed by default on many Linux distributions (e.g. `apt install lld`).
35+
3236
## Contributing to Turborepo
3337

3438
### Building Turborepo

0 commit comments

Comments
 (0)