-
Notifications
You must be signed in to change notification settings - Fork 14k
Description
Linking rustc with custom linker is awkward
There are two “easy” ways I can think of to use a custom linker:
-
Delegate to an existing linker/compiler
Tell an existing linker or compiler to use your binary for the actual linking.
For example:RUSTFLAGS="-Clinker=clang -Clink-arg=--ld-path=your-custom-linker"However, you can’t specify this for all builds in
bootstrap.toml.
You can set the linker explicitly — but not the-Clink-arg, since there’s no way to specifyRUSTFLAGSor this flag directly there. -
Symlink your custom linker to the linker rustc uses
For example:RUSTFLAGS="-Clinker-features=-lld"and symlinking the default system linkerRUSTFLAGS="-Clink-self-contained=-linker"and symlinkinglld
This should be possible to configure in
bootstrap.toml, but I couldn’t get it working.
Settingrust.bootstrap-override-lld = "external"inbootstrap.tomlshould roughly be equivalent to disabling self-contained linker, but it doesn’t seem to work.
Right now, to keep linking rustc with a custom linker, I have to always set the RUSTFLAGS variable, which is really cumbersome — and bootstrap.toml should offer a way to persist such settings.
Is there a reason why bootstrap.toml doesn’t support rustflags option like Cargo config.toml does?
Proposed fixes
- Make
rust.bootstrap-override-lldactually functional: fix: disable self-contained linker when bootstrap-override-lld is set #148709 - Add a way to specify linker arguments or general
RUSTFLAGSinbootstrap.toml