Skip to content

Commit

Permalink
Switch from ld (the default linker) to using lld for GNU Linux targets (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
bgw committed May 17, 2024
1 parent 84ef2da commit 1299d8d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ rustdocflags = ["-Znormalize-docs"]
[target.x86_64-pc-windows-msvc]
linker = "rust-lld"

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

[target.x86_64-apple-darwin]
linker = "rust-lld"
[target.'cfg(all(target_os = "linux", target_env = "gnu"))']
rustflags = [
"--cfg",
"tokio_unstable",
"-Zshare-generics=y",
"-Zthreads=8",
"-Csymbol-mangling-version=v0",
"-Clink-arg=-fuse-ld=lld",
]

[alias]
xtask = "run --package xtask --"
Expand Down
5 changes: 5 additions & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ runs:
# we want more specific settings
cache: false

- name: "Install LLD (LLVM Linker) for Linux"
if: runner.os == 'Linux'
shell: bash
run: sudo apt-get -y update && sudo apt-get install -y lld

- name: "Set Windows default host to MinGW"
if: ${{ inputs.windows == 'true' }}
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Thanks for your interest in contributing to Turbo!
- [Rust](https://www.rust-lang.org/tools/install)
- [cargo-groups](https://github.com/nicholaslyang/cargo-groups) (used to group crates into Turborepo-specific ones and Turbopack-specific ones)

### Linux Dependencies

- LLD (LLVM Linker), as it's not installed by default on many Linux distributions (e.g. `apt install lld`).

## Contributing to Turborepo

### Building Turborepo
Expand Down

0 comments on commit 1299d8d

Please sign in to comment.