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

Add support for applying cargo:rustc-link-lib link commands to specific outputs #7020

Open
robmv opened this issue Jun 7, 2019 · 1 comment
Labels
A-build-scripts Area: build.rs scripts A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@robmv
Copy link

robmv commented Jun 7, 2019

Describe the problem you are trying to solve

It isn't possible to tell cargo via a build script that some libraries must be linked only to some outputs, for example if the crate has multiple output binaries, there should be a way to tell cargo that a library must be linked to only one binary.

My use case is that when building for the Windows platform, each binary needs to be linked to its own resources file (Resource Compiler), each binary needs a different rc applied. Currently the build script can compile each rc file, but it isn't possible to indicate the binary it applies using:

cargo:rustc-link-lib=dylib=myresourcelib

Describe the solution you'd like

Maybe extending the syntax of the cargo:rustc-link-lib command to something like:

cargo:rustc-link-lib=type[:name]=dylib=myresourcelib

Where type[:name] could be for example: bin:mybinary1 or lib if it applies to a shared library.

Notes

Currently all this could be done outside of cargo, for example with an external build tool that append the compiled resource file after cargo finishes building them, but as this could be done on the linking phase, It would be helpful to avoid the need for another tools.

This has some other practical uses outside of linking with resource files, an example could be producing two binaries that link to different implementations of the same FFI function, among other things.

@robmv robmv added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jun 7, 2019
@ehuss ehuss added A-linkage Area: linker issues, dylib, cdylib, shared libraries, so A-build-scripts Area: build.rs scripts labels Jun 24, 2019
@AlexTMjugador
Copy link
Contributor

I'd like to add that the current restrictions also make it impossible to link a resource file to an executable when compiling a package that contains both binary and library crates, because the resource is linked to the library and not the binary.

@epage epage added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

4 participants