Cargo add [version suitable for my non-latest rustc]

Hello, I'm on rust 1.63 installed with a package manager on OpenBSD. I install clap with

cargo add clap

and after cargo build it says

error: package clap_lex v0.3.1 cannot be built because it requires rustc 1.64.0 or newer, while the currently active rustc version is 1.63.0

I want to install some of the latest set [library, its dependences] suitable for my exact version of rustc. I do not want to upgrade rust before my OS gets the newer package.



I don't believe there is a way of saying 'get me the latest version that is compatible with an old Rust' - the rust-version field of Cargo.toml (which is what causes this error message) does not factor into version resolution. There has been discussion of adding that in the past, but it's not something that's currently implemented.

With that in mind, your best bet is to look at the changelog for the library you're trying to use:

It mentions that the MSRV (minimum supported Rust version) was increased to 1.64.0 in version 4.1.0. So you need to use 4.0.x, by the sounds of it.

cargo add clap@4.0

CC @epage, who may be interested in this UX from more than one perspective.

There are a couple of potential things to improve here. Most of this centers around improving the MSRV experience. I've been collecting a list of potential solutions in the libc thread.

A couple in particular

1 Like

Thanks. At least that somehow helps. But some libraries has a lot of deps, so that is not that easy on practice.
Anyway, as a novice, I'll learn a lot about libraries and read their docs, at Changelogs :wink:

But really that bores, to be true ;-(

Unfortunately, this will be an endless struggle. Rust doesn't have any features to properly support anything older than latest stable, so trying to use an older version will be fragile and need special care.

I wrote LTS — Cargo add-on // that can rewind the crate index or remove problematic crates that break on old versions. I planned to use msrv stats to create a selective backwards-compatible index, but never finished that.

In the end, I'd recommend uninstalling Rust from your OS, and using Rust from rustup instead. It will be way easier and more compatible.

1 Like

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.