Per-crate linking option in Cargo manifest #12848
Labels
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
One Rust package may contain a single library crate and multiple binary crates. If only one binary crate needs to link with a C native library, then it doesn't quite make sense to link that native library with the library crate, because
Currently the only way to configure per-crate linking option seems to be using cargo:rustc-link-arg-bin=BIN=FLAG. This requires some effort in the build script, and still doesn't show native library dependencies in documented format.
Proposed Solution
It would be much nicer if each crate lists its own linking dependencies in
Cargo.toml
like this:or
Programmers won't need
#link
attribute or cargo:rustc-link-lib=LIB build script instruction in many use cases.Notes 1
Currently
Cargo.toml
may contain these fields to override build scripts:However this applies to whole package not per crate.
Notes 2
Currently, Cargo on
cargo:rustc-link-lib
passes-l <lib>
to rustc when compiling the lib crate. What I'm looking for is Cargo passing-l <lib>
to bin crates on a similar build script instruction or a bin-crate option inCargo.toml
.The text was updated successfully, but these errors were encountered: