Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused-crate-dependencies conflicts in lib and bin crates #12854

Closed
tae-soo-kim opened this issue Oct 19, 2023 · 2 comments
Closed

unused-crate-dependencies conflicts in lib and bin crates #12854

tae-soo-kim opened this issue Oct 19, 2023 · 2 comments
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) C-bug Category: bug S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

Comments

@tae-soo-kim
Copy link

Problem

Cargo.toml

[package]
name = "hello"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "*"

src/lib.rs

#![deny(unused_crate_dependencies)]

src/main.rs

#![deny(unused_crate_dependencies)]

use hello as _;
use libc;

fn main() {
    let _: libc::size_t = 0;
}

In package hello, libc is needed by bin crate, not lib crate.

Steps

To reproduce, run cargo build. The build fails.

Possible Solution(s)

Because libc is needed by the bin crate, we have to list it as a package dependency. But then the lib crate complains.

One possible solution is to have each crate specify its own dependencies. The package-level dependencies would then be the union of all crate-level dependencies. But crate-level dependencies make more sense because users of a package may not want everything in the package. For example a user merely interested in using the library crate shouldn't be forced to pull dependencies required by binary crates.

Notes

No response

Version

No response

@tae-soo-kim tae-soo-kim added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Oct 19, 2023
@weihanglo
Copy link
Member

weihanglo commented Oct 19, 2023

Thanks for the report. This seems like a duplicate of rust-lang/rust#95513 and rust-lang/rust#57274 and others alike. Close in favor of those.

@weihanglo weihanglo added A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix and removed S-triage Status: This issue is waiting on initial triage. labels Oct 19, 2023
@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) C-bug Category: bug S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix
Projects
None yet
Development

No branches or pull requests

2 participants