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.
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
--libflag to select the library Cargo target. If there is only one Cargo target, and it is a library, then the--libflag 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
CargoRustcPrintCfgbuilder 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--libis a problem. So, this crate needs to be smarter about selecting the Cargo target and avoid blindly using the--libflag.I am currently thinking of using the cargo-metadata crate to obtain a list of Cargo targets and determine usage of the
--libflag or--binflags based on the Cargo targets listed.