How to use -Z minimal-versions with optimistic crate

Say I use a crate that claims to be happy with an older version of one of its dependencies, but doesn't build using -Z minimal-versions. That might be due to sloppiness on their part or I may be developing on a peculiar platform that the older version doesn't support. Can I enforce a tighter version than the crate specifies for its dependencies? Can I still use -Z minimal-versions to asses any other dependencies?

E.g. this program:

fn main() { clap::Command::new(""); }

with Cargo.toml specifying:

clap = "3.1.0"

prepared using cargo update -Z minimal-versions and built with nightly or stable Rust on Windows x64 tries in vain to build winapi-0.2.4 my system (and at least one other) but most likely works fine on non-windows platforms.

1 Like

Sometimes you can find which dependency is selected in too-old version (see cargo tree), and add this dependency to your Cargo.toml with a higher version.

If you identify which of your dependencies specified their deps too low, you should ask them to bump their deps, and then require the latest version of that crate.

However, it may turn out to be whack-a-mole needing fixing dozens of dependencies. The breakage with -Z minimal-versions is unfortunately a known widespread problem.


Add it how and what for? All I can think of is a normal dependency, or probably dev-dependency, on a higher version. I guess that implies an early, distinct error failed to select a version for the requirement ‘winapi = "^9.9.9"’ for users who somehow get your crate or program and don't get that higher version of the awkward sub-dependent crate (I'm not sure what is possible here so I assume anything is). This could become a problem itself if one day a new version of the optimistic crate drops its dependency on the awkward crate altogether. It wouldn't allow still using -Z minimal-versions for other dependencies.

I didn't find anything about minimal versions even mentioning that dependencies can be platform specific and therefore minimal versions are. For my case, structopt or clap are user interfaces, which tend to be platform specific but also live on the outskirts of the project, and therefore you can disable them (dependency and code) while checking minimal versions.

Even platform specific dependencies for a different platform contribute to dependency resolution. All dependencies of the whole workspace are resolved together unconditionally and stored in Cargo.lock.

1 Like

Good to know, one can indeed see the multiple winapi versions doing cargo update -Z minimal-versions on Linux. But does that change the issue here? You can build the above program fine on Linux with minimal versions. Do you imply that clap's dependencies are sloppy and there's enough reason to bother Linux users with an update? I think they're merely not ideal for everyone.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.