Extend rustc-link-args to support individual examples/tests/benches. #11801
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-triage
Status: This issue is waiting on initial triage.
Problem
Cargo does not appear to support passing extra link arguments on a per example basis. This poses a problem for my project which requires a specialized extra linking step to occur for any executable that uses my library.
I saw that #9557 added support for passing extra link flags via a build script that allows some level of customization at the target level. However, while you can pass extra link flags to all your examples via
cargo:rustc:link-arg-examples=FLAG
, you cannot pass extra flags to a specific, single example.This is supported for package binaries via
cargo:rustc-link-arg-bin=BIN=FLAG
in a build script, which is the workaround I'm using currently, but it would be very helpful if this specification syntax was extended to examples, and probably the rest of target types as well (benches, tests,... is that all?)The reason why just using package binaries in place of examples is a problem is that I cannot then build with dev.dependencies, which would be quite useful since these binaries very much are examples: they are meant to demonstrate how to use the library in a broader context, which will likely include external crates. Demonstrating usage of my library through examples is all the more important given the relatively unorthodox extra linking step that is required.
Proposed Solution
Essentially just complete what appears to already be considered future work in this department. Namely, add build commands of the form
I
Notes
If you are curious about why I need this extra linking step: I perform some code generation based on artifacts that may or may not be accompanying a binary that uses my package. That generated code gets compiled and then needs to be linked into the final executable. The code generation is done by another binary that gets included in my package, and is conceptually just part of using the package.
The text was updated successfully, but these errors were encountered: