Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
curldivergence opened this issue Jun 4, 2021 · 7 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@curldivergence
Copy link

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!

@curldivergence curldivergence added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jun 4, 2021
@ehuss
Copy link
Contributor

ehuss commented Jun 4, 2021

Have you checked out the rustc-link-arg feature? That allows you to specify per-binary linker arguments in a build script. It is currently only on nightly, but would be good to have someone test it out.

@curldivergence
Copy link
Author

@ehuss Unfortunately I don't see this option as available on rustc 1.54.0-nightly (cc77ba46f 2021-06-03) (as I understand, I should be able to see it in the output of rustc.exe -Z help?)

@ehuss
Copy link
Contributor

ehuss commented Jun 4, 2021

The -Z flag is passed to cargo, not rustc. It should be listed in cargo -Z help.

@curldivergence
Copy link
Author

@ehuss, it worked!! Thank you very much, you really saved the day :)
image
I was about to start writing custom build scripts for manual rustc invocation for each library example :)

I think we won't need the feature I have requested when your option is stabilized, so please feel free to close the issue.

@curldivergence
Copy link
Author

However, I have one more question: is there a possibility to add this option to cargo config or manifest so that one doesn’t have to use it explicitly on command line?

@curldivergence
Copy link
Author

@ehuss, also, judging from the fact this option is pretty young I can guess it's kind of early to ask this, but anyway, is there any sort of vision regarding the timeline of stabilization of this flag? Thanks!

@ehuss
Copy link
Contributor

ehuss commented Jun 10, 2021

Before it is stabilized, you can place it in the [unstable] config section (described here) so you don't have to specify it on the command-line.

There is a proposal to stabilize it at #9557. I'm not sure how long it will take, though. We just discovered an issue with the implementation which will need to be resolved first.

Closing since this seems to be resolved.

@ehuss ehuss closed this as completed Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants