ana
September 9, 2025, 10:06pm
1
I've set up mold as my default linker in $HOME/.cargo/config.toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]
How do I fall back to the default Rust linter for a single project?
I've tried setting linker = "" / "clang" / "gcc" / "ld" / "ldd" and rustflags = [], but no combination seems to works.
1 Like
kornel
September 10, 2025, 10:06am
2
I think this is a deficiency in Cargo's ability to configure the linker:
opened 03:35AM - 15 Nov 22 UTC
A-configuration
C-feature-request
A-rustflags
S-triage
### Problem
I'm thinking of if it is possible to use rust-lld installed by `r… ustup component add llvm-tools-preview` using a one-line config like `linker=rust-lld`. Currently configuring it on macOS is relatively hard.
Basically what I'm doing now is like:
```
rustflags = [
"-Clink-arg=-fuse-ld=/Users/skyzh/.rustup/toolchains/nightly-2022-10-16-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/gcc-ld/ld64.lld",
]
```
Probably we can do something to make the configuration easier?
### Proposed Solution
If `linker = 'rust-lld'` in `config.toml`, we can automatically generate the args for rustc by appending
```
"-Clink-arg=-fuse-ld=${RUSTUP_TOOLCHAIN_PATH}/lib/rustlib/${ARCH}/bin/gcc-ld/ld64.lld"
```
to rustflags, so that we can easily use the rust-lld linker installed with rustup.
### Notes
_No response_
because Cargo doesn't understand rustflags content and can't undo the selection made there.
You'd have to ensure the rustflags are replaced instead of merged. Setting RUSTFLAGS env var may do the trick, but it will also replace flags from other layers of the configuration.
system
Closed
December 9, 2025, 10:07am
3
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.