Add support for applying cargo:rustc-link-lib link commands to specific outputs #7020
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.
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:
Describe the solution you'd like
Maybe extending the syntax of the
cargo:rustc-link-lib
command to something like:Where
type[:name]
could be for example:bin:mybinary1
orlib
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.
The text was updated successfully, but these errors were encountered: