Skip to content

Commit 1eb5944

Browse files
authored
Switch from ld (the default linker) to using lld for GNU Linux targets (#65898)
Copies changes from vercel/turborepo#8166, and updates contributing documentation to include the installation of lld. > **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 b113937 commit 1eb5944

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

.cargo/config.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@ rustflags = ["-C", "target-feature=+crt-static"]
2222
[target.aarch64-pc-windows-msvc]
2323
linker = "rust-lld"
2424

25-
[target.aarch64-apple-darwin]
25+
[target.'cfg(target_os = "macos")']
2626
linker = "rust-lld"
2727

28-
[target.aarch64-unknown-linux-gnu]
29-
linker = "aarch64-linux-gnu-gcc"
28+
[target.'cfg(all(target_os = "linux", target_env = "gnu"))']
29+
rustflags = [
30+
"--cfg",
31+
"tokio_unstable",
32+
"-Zshare-generics=y",
33+
"-Zthreads=8",
34+
"-Zunstable-options",
35+
"-Csymbol-mangling-version=v0",
36+
"-Clinker-flavor=gnu-lld-cc",
37+
"-Clink-self-contained=+linker",
38+
]
3039

3140
[target.aarch64-unknown-linux-musl]
3241
linker = "aarch64-linux-musl-gcc"

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ runs:
1616
rustflags: ''
1717
cache: false
1818

19+
- name: 'Install LLD (LLVM Linker) for Linux'
20+
if: runner.os == 'Linux'
21+
shell: bash
22+
run: sudo apt-get -y update && sudo apt-get install -y lld
23+
1924
- name: 'Add cargo problem matchers'
2025
shell: bash
2126
run: echo "::add-matcher::${{ github.action_path }}/matchers.json"

contributing/core/developing.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
- All pull requests should be opened against `canary`.
55
- The changes on the `canary` branch are published to the `@canary` tag on npm regularly.
66

7-
To develop locally:
7+
## Dependencies
8+
9+
- Install Rust and Cargo via [rustup](https://rustup.rs).
10+
- Install the [GitHub CLI](https://github.com/cli/cli#installation).
11+
- Enable pnpm:
12+
```
13+
corepack enable pnpm
14+
```
15+
- (Linux) Install LLD, the LLVM linker:
16+
```
17+
sudo apt install lld
18+
```
19+
20+
## Local Development
821

9-
1. Install Rust and Cargo via [rustup](https://rustup.rs).
10-
1. Install the [GitHub CLI](https://github.com/cli/cli#installation).
1122
1. Clone the Next.js repository (download only recent commits for faster clone):
1223
```
1324
gh repo clone vercel/next.js -- --filter=blob:none --branch canary --single-branch
@@ -16,10 +27,6 @@ To develop locally:
1627
```
1728
git checkout -b MY_BRANCH_NAME origin/canary
1829
```
19-
1. Enable pnpm:
20-
```
21-
corepack enable pnpm
22-
```
2330
1. Install the dependencies with:
2431
```
2532
pnpm install

0 commit comments

Comments
 (0)