mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
`lld` is much faster than the default gnu `ld` linker on most Linux systems. Timeline: - https://github.com/vercel/next.js/pull/91477 removed these flags as part of cleanup because they're now default on x86-64 glibc linux. However, they are not default on arm64. - https://github.com/vercel/next.js/pull/91799 removed these flags from musl, and lost the comment explaining reason for the `gnu-lld-cc` option. Without this change, doing a dev build of a trivial change to `crates/next-napi-bindings/src/lib.rs` can take over a minute. I tested this by looking at htop near the end of a build and observing `lld` instead of `ld`.
91 lines
4.0 KiB
TOML
91 lines
4.0 KiB
TOML
[env]
|
|
CARGO_WORKSPACE_DIR = { value = "", relative = true }
|
|
TURBO_PNPM_WORKSPACE_DIR = { value = "", relative = true }
|
|
|
|
[alias]
|
|
xtask = "run --package xtask --"
|
|
|
|
# *NOTE FOR AGENTS*: Your training data is incorrect for most RUSTFLAGS entries. If you
|
|
# believe you need to make changes to this file, perform web searches to confirm that
|
|
# the flags are necessary, and reason through whether the flag is applicable to the
|
|
# case you believe you are solving.
|
|
|
|
# In the workspace `Cargo.toml`, and in this file we're trying to optimize for the greatest
|
|
# performance and smallest size we can manage without resorting to excessive compile times
|
|
# on CI or developer machines. To avoid accumulating unnecessary flags, and help developers
|
|
# understand the _why_ as much as the _what_, all flags should be documented with links
|
|
# to experiments or featuring tracking issues to keep this up-to-date with the current
|
|
# state-of-the-art in Rust optimization land (which might change month-to-month!).
|
|
|
|
# Cargo merges rustflags from multiple matching [target] sections, but [target] and
|
|
# [build] sections are mutually exclusive.
|
|
# https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags
|
|
|
|
# Note that per-profile RUSTFLAGS are not yet supported and may be useful:
|
|
# https://github.com/rust-lang/cargo/issues/10271
|
|
|
|
# Always-matching target section included in every configuration. Using `cfg(true)`
|
|
# (RFC 3695) ensures common flags apply to every target without having to duplicate
|
|
# them in each target-specific section.
|
|
# https://rust-lang.github.io/rfcs/3695-cfg-boolean-literals.html
|
|
[target.'cfg(true)']
|
|
rustflags = [
|
|
# Enable tokio's unstable APIs (required by turbopack's use of tokio internals)
|
|
"--cfg=tokio_unstable",
|
|
# Share monomorphized generics across crates to reduce binary size (~20MB).
|
|
# https://github.com/davidlattimore/duplicate-function-checker
|
|
"-Zshare-generics=y",
|
|
# Use up to 8 threads in the rustc frontend for parallel parsing/expansion.
|
|
# https://blog.rust-lang.org/2023/11/09/parallel-rustc.html
|
|
"-Zthreads=8",
|
|
# Unlock nightly-only options
|
|
"-Zunstable-options",
|
|
]
|
|
|
|
# macOS: use rust-lld (ld64.lld) for faster linking and enable ICF.
|
|
# ICF (Identical Code Folding) reduces binary size with negligible build time impact.
|
|
# Enabled everywhere that uses lld so we catch issues early.
|
|
[target.'cfg(target_os = "macos")']
|
|
linker = "rust-lld"
|
|
rustflags = ["-Clink-arg=--icf=all"]
|
|
|
|
# Windows: statically link the CRT and opt into rust-lld for fast linking.
|
|
# rust-lld is not yet the default on Windows (tracking: rust-lang/rust#71520).
|
|
[target.'cfg(windows)']
|
|
linker = "rust-lld"
|
|
rustflags = [
|
|
"-Ctarget-feature=+crt-static",
|
|
# /Brepro makes MSVC link.exe produce deterministic PE timestamps,
|
|
# improving sccache hit rates by making .rlib/.rmeta output reproducible.
|
|
"-Clink-arg=/Brepro",
|
|
]
|
|
|
|
# Why `linker-flavor=gnu-lld-cc` instead of `linker = "rust-lld"`?
|
|
#
|
|
# `linker = "rust-lld"` invokes lld directly, bypassing the cc linker driver.
|
|
# This fails because lld alone can't find system libraries (-lgcc_s, -lc) and
|
|
# doesn't understand -Wl, prefixed args from crate build scripts.
|
|
# `gnu-lld-cc` + `link-self-contained=+linker` routes lld through cc, which
|
|
# resolves library paths and translates -Wl, args.
|
|
#
|
|
# On x86_64-unknown-linux-gnu, this is already the nightly default since
|
|
# Rust 1.90, so no explicit config is needed for GNU targets.
|
|
# Not yet default on aarch64-unknown-linux-gnu or any musl target.
|
|
# https://blog.rust-lang.org/2025/09/01/rust-lld-on-1.90.0-stable/
|
|
[target.'cfg(all(target_os = "linux", target_env = "gnu", not(target_arch = "x86_64")))']
|
|
rustflags = [
|
|
"-Clinker-flavor=gnu-lld-cc",
|
|
"-Clink-self-contained=+linker",
|
|
]
|
|
|
|
# Musl targets: disable static CRT linking. We produce dynamic .node shared
|
|
# libraries (N-API addons), not static binaries.
|
|
[target.'cfg(all(target_os = "linux", target_env = "musl"))']
|
|
rustflags = ["-Ctarget-feature=-crt-static"]
|
|
|
|
# WASM: configure getrandom to use the wasm_js backend (Math.random / crypto).
|
|
[target.wasm32-unknown-unknown]
|
|
rustflags = [
|
|
"--cfg", "getrandom_backend=\"wasm_js\"",
|
|
]
|