Skip to content

Add detection of multiple targets and select one #5

@volks73

Description

@volks73

An error occurs if there is more than one Cargo target defined in a package's manifest (Cargo.toml), so the default is to add the --lib flag to select the library Cargo target. If there is only one Cargo target, and it is a library, then the --lib flag is functionally a "no-op". However, if there is only one Cargo target and it is a binary, or multiple binary Cargo targets are defined with no library target, then another error occurs: "no library targets found in package <PACKAGE_NAME>.

The CargoRustcPrintCfg builder allows for customization of the command to select the appropriate Cargo target to avoid this error, but if this crate is used within another crate, it may not be possible to customize the command for the two cases where the --lib is a problem. So, this crate needs to be smarter about selecting the Cargo target and avoid blindly using the --lib flag.

I am currently thinking of using the cargo-metadata crate to obtain a list of Cargo targets and determine usage of the --lib flag or --bin flags based on the Cargo targets listed.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions