Is Cargo.lock wrong?

I was wondering why cargo deny warns about Windows stuff, even though Iโ€™m on Linux. I found this comes from Cargo.lock indifferently listing unconfigured (and build) dependencies:

[[package]]
name = "stacker"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce"
dependencies = [
 "cc",
 "cfg-if",
 "libc",
 "psm",
 "winapi",
]

[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
 "winapi-i686-pc-windows-gnu",
 "winapi-x86_64-pc-windows-gnu",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
โ€ฆ

This comes from

โ€ฆ
[dependencies.psm]
version = "0.1.7"

[build-dependencies.cc]
version = "1.0.2"

[target."cfg(windows)".dependencies.winapi]
version = "0.3.6"
features = [โ€ฆ

cargo tree shows what I suppose is really going on

โ”œโ”€โ”€ lettre v0.11.7
โ”‚   โ”œโ”€โ”€ chumsky v0.9.3
โ”‚   โ”‚   โ”œโ”€โ”€ โ€ฆ
โ”‚   โ”‚   โ””โ”€โ”€ stacker v0.1.15
โ”‚   โ”‚       โ”œโ”€โ”€ cfg-if v1.0.0
โ”‚   โ”‚       โ”œโ”€โ”€ libc v0.2.155
โ”‚   โ”‚       โ””โ”€โ”€ psm v0.1.21
โ”‚   โ”‚           [build-dependencies]
โ”‚   โ”‚           โ””โ”€โ”€ cc v1.0.99
โ”‚   โ”‚       [build-dependencies]
โ”‚   โ”‚       โ””โ”€โ”€ cc v1.0.99
โ”‚   โ”œโ”€โ”€ โ€ฆ

Whoโ€™s right? I hope the last output. But then why does Cargo.lock have so much stuff which is not even in my build?

Cargo.lock has to be platform agnostic, otherwise it would change every time people on different platforms build, which would be unacceptable for a file meant to be checked in to your repository.

6 Likes

:+1:, that's exactly the issue here.

We've discussed one day supporting "this crate supports only these targets", and in that circumstance we could limit the contents of the lock. That would be useful for a variety of use cases. But in the absence of that, yeah, the lockfile has to support every target.

3 Likes

Hmm, annoying for code that will never come near Windows.

But no need for many ignores: deny.toml already had my target "x86_64-unknown-linux-musl" โ€“ I only needed to remove the comment and those warnings went away. :grinning:

2 Likes

See also Allow workspaces/crates to limit support to an explicit set of targets ยท Issue #11313 ยท rust-lang/cargo ยท GitHub.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.