Closed joshtriplett closed 2 years ago
This actually appears to be a cargo bug with weak dependencies (related https://github.com/rust-lang/cargo/issues/10801). cargo-deny relies on the output of cargo metadata
to know which dependencies were selected for each package based on the top level features selected, the output for weak dependencies is unfortunately wrong both for metadata and Cargo.lock
# Cargo.toml
[package]
name = "test"
[dependencies]
git2 = { version = "0.14", default-features = false, features = [
"zlib-ng-compat",
] }
{
"id": "libgit2-sys 0.13.4+1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dependencies": [
"cc 1.0.73 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.126 (registry+https://github.com/rust-lang/crates.io-index)",
"libssh2-sys 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)"
],
"deps": [
{
"name": "cc",
"pkg": "cc 1.0.73 (registry+https://github.com/rust-lang/crates.io-index)",
"dep_kinds": [
{
"kind": "build",
"target": null
}
]
},
{
"name": "libc",
"pkg": "libc 0.2.126 (registry+https://github.com/rust-lang/crates.io-index)",
"dep_kinds": [
{
"kind": null,
"target": null
}
]
},
{
"name": "libssh2_sys",
"pkg": "libssh2-sys 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"dep_kinds": [
{
"kind": null,
"target": null
}
]
},
{
"name": "libz_sys",
"pkg": "libz-sys 1.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"dep_kinds": [
{
"kind": null,
"target": null
}
]
},
{
"name": "pkg_config",
"pkg": "pkg-config 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)",
"dep_kinds": [
{
"kind": "build",
"target": null
}
]
}
],
"features": [
"zlib-ng-compat"
]
},
Here we can see that even though the correct feature is enabled, the libssh2-sys
dependency is still included even though it is weak and not explicitly enabled. While (at least according to the above cargo issue) cargo internally does make this an actual weak dependency and thus won't compile the tree rooted at libssh2-sys
, and cargo tree
prints out the expected tree, the same resolution logic doesn't seem to apply to cargo metadata
.
Luckily, this bug can be worked around, but is not specific to cargo-deny itself, but rather the crate it uses to build the crate graph itself, so I'm transferring the issue there.
Resolved by #42
Describe the bug
cargo deny check bans
errors out saying a banned package appears in dependencies, even if that package only appears in a weak dependency feature that isn't activated.To Reproduce Steps to reproduce the behavior:
git2
version0.14.4
, withdefault-features = false
, andfeatures = ["zlib-ng-compat"]
.cargo tree
and observe nolibssh2-sys
oropenssl-sys
dependency.deny.toml
that bansopenssl-sys
.cargo deny check bans
, and get this output:Expected behavior
cargo deny check bans
should understand that there's no dependency onopenssl-sys
(orlibssh2-sys
) here.