chore: switch default linker to mold for faster builds
Summary
Switch the workspace's default linker from the platform default (GNU ld.bfd on Linux) to mold for local cargo build/cargo check/cargo test, and for the Dockerfile builder stage that compiles the 13 workspace service binaries — to cut link time in both the dev inner loop and devstack image builds.
Why
Link time is a fixed, serial tail on every incremental build regardless of how little source changed — a meaningful cost in this workspace (61 crates, many binaries per the Dockerfile builder stage: craig-rules, craig-cases, craig-placement, etc.). mold is currently the fastest general-purpose ELF linker available, typically several times faster than ld.bfd/ld.gold and meaningfully faster than lld on large multi-crate Rust workspaces. Local experiments confirm the project compiles cleanly under mold, including in the Alpine/musl builder image.
Alternatives considered
| Option | Speed | Maturity | Notes |
|---|---|---|---|
| mold (proposed) | Fastest | Stable, widely adopted (used by rustc itself, Chromium, etc.) | AGPL-3.0/commercial dual-licensed — dev/build tooling only, never linked into shipped binaries, so no license entanglement with our AGPL-3.0-or-later distribution. Confirmed working against this workspace, including the musl builder image |
lld (LLVM) |
Fast, close 2nd | Stable, mature | Not needed — mold already confirmed working everywhere we need it |
wild |
Fast in early benchmarks | Pre-alpha upstream — missing key features, not recommended for production use | Rejected for now; revisit once it reaches a stable/beta release |
ld.gold |
Slower than lld/mold | Deprecated in recent binutils | Not worth adopting |
default ld.bfd |
Slowest | Baseline | Status quo |
Acceptance criteria
-
.cargo/config.tomlsetsmoldas the linker for the relevant Linux target(s) (e.g.rustflags = ["-C", "link-arg=-fuse-ld=mold"]under[target.x86_64-unknown-linux-gnu]), scoped so it doesn't break environments wheremoldisn't installed -
Dockerfilebuilder stage (rust:alpine) installsmoldand uses it for thecargo build -p craig-rules -p craig-cases -p ...step; runtime stage is unaffected (no linker needed post-build) -
docs/modules/ROOT/pages/local-dev.adocdocuments themolddependency and per-platform install steps - Before/after clean-build and incremental-build timing recorded in the MR description (both local and devstack image build)
Context / references
rust-toolchain.toml— pinschannel = "1.97.0", the toolchain this targets.cargo/config.toml— currently only has an[alias]section, no linker configDockerfile:27,72-73— Alpine/musl builder stageCOPY . .+cargo buildsteps- github.com/rui314/mold
- github.com/davidlattimore/wild (pre-alpha, not adopted here)