Skip to content

Cargo doesn't allow to pass extra linker arguments per binary or for examples #9542

@curldivergence

Description

@curldivergence

Hello, I need to export some specific symbols from the binaries that use my library (including the examples that are in the same crate), and to do this, I have to pass some extra linker args since nothing is exported by default. But unfortunately, .cargo/config.toml doesn't allow to specify extra compiler/linker args with fine granularity: it applies the build.rustflags option contents to every compiler call, which is unfortunate since the dependencies of my library (and my library itself) do not contain the required symbols and thus fail to link.

Ideally, I'd love to have a language attribute that would allow forwarding extra compiler args from source, but it looks like a serious and probably controversial change, so I believe this issue should be handled on cargo level.
As to my taste, the most obvious place to put extra flags is cargo.toml (since it's the place where some people, including me and the reporter of #3261, have tried to put this flag :)), but since it has not been done already, I can guess there are some arguments against it? So please share your thoughts.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions