Skip to content

Linking rustc with custom linker is awkward #148708

@karolzwolak

Description

@karolzwolak

Linking rustc with custom linker is awkward

There are two “easy” ways I can think of to use a custom linker:

  1. 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 specify RUSTFLAGS or this flag directly there.

  2. Symlink your custom linker to the linker rustc uses
    For example:

    • RUSTFLAGS="-Clinker-features=-lld" and symlinking the default system linker
    • RUSTFLAGS="-Clink-self-contained=-linker" and symlinking lld

    This should be possible to configure in bootstrap.toml, but I couldn’t get it working.
    Setting rust.bootstrap-override-lld = "external" in bootstrap.toml should 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

Metadata

Metadata

Assignees

Labels

A-bootstrap-configArea: bootstrap `config.toml` and the config systemA-linkersArea: linkers... you gotta love linkersT-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions