Find the minimum supported Rust version (MSRV) for your project
Find the minimum supported Rust version (MSRV) for your project
This crate can assist you in finding the Minimum Supported Rust Version for a crate.
In this readme you'll find everything to get you started. You can find more detailed explanations in the cargo-msrv book.
⌘ preview - prerequisites - install - usage - JSON output format - a short history - license
⌘ preview - prerequisites - install - usage - JSON output format - a short history - license
Rustup is required for the cargo msrv (find) and cargo msrv verify commands.
⌘ preview - prerequisites - install - usage - JSON output format - a short history - license
| cargo | supported | command |
|---|---|---|
| stable | $ cargo install cargo-msrv --locked |
|
| development | ❌ |
| cargo | supported | command |
|---|---|---|
| stable | $ cargo install --git https://github.com/foresterre/cargo-msrv.git --tag v0.19.3 cargo-msrv |
|
| development | $ cargo install --git https://github.com/foresterre/cargo-msrv.git cargo-msrv |
| cargo | supported | command |
|---|---|---|
| stable | $ cargo binstall --no-confirm cargo-msrv |
|
| development | ❌ |
pacman -S cargo-msrvYou can use the following commands for building and running via Docker:
$ docker build -t cargo-msrv .$ docker run -t -v "$(pwd)/Cargo.toml":/app/Cargo.toml cargo-msrvDocker images are also available on Docker Hub.
⌘ preview - prerequisites - install - usage - JSON output format - a short history - license
cargo msrv find
or cargo msrv find --linear to find the MSRV for a
Cargo project in your current working directory.cargo msrv --path find to find the MSRV for a
Cargo project in the `` directory.cargo msrv find -- to use `` as the
compatibility check which decides whether a Rust version is
compatible or not. This command should be runnable through rustup as rustup run .cargo msrv find -- cargo check --tests.cargo msrv find -- cargo check --ignore-rust-version. Only available on Rust >= 1.56.cargo msrv verify to verify the MSRV as specified
by a crate authorpackage.rust-version (Rust >=1.56) or the package.metadata.msrv
key in the 'Cargo.toml' manifest. See
the book for a more detailed
description.cargo msrv list to list the MSRV's of your
dependencies as specified by their authorscargo msrv show to show the currently specified MSRVPlease refer to the commands chapter in the cargo-msrv book for more detailed descriptions of the supported (sub) commands.
Options
…⌘ preview - prerequisites - install - usage - JSON output format - a short history - license
JSON output may be enabled by providing the --output-format json flag: cargo msrv find --output-format json.
Events are printed as json lines. The event type is indicated by the type key.
Please see the Output formats and Output format: JSON chapters of the book for documentation of this output format.
⌘ preview - prerequisites - install - usage - JSON output format - a short history - license
An excerpt
cargo-msrvwas originally born out of a desire to find the MSRV for a Rust project (more specifically package). MSRV stands for "minimal supported Rust version" and is the earliest or oldest version supported by a Rust project. For different projects this may mean different things, but for this post I will consider "support" as "does compile with a Rust toolchain of a certain version".Fast forward a few years, and the MSRV has become somewhat more ubiquitous which can also be seen by its inclusion into Cargo as the rust-version. Over time some additional tools were added to
cargo-msrv. One of these was thecargo msrv verifysubcommand.This subcommand can be used to check whether a Rust project supports its defined MSRV (e.g. via this
rust-versionfield in the Cargo manifest). For example, in a CI pipeline you can use this to check whether your project works for the version you promised to your users.Originally, I kept the
cargo msrvtop level command aside from the subcommands for backwards compatibility reasons. In hindsight I probably shouldn't have done that, but as is, their coexistence at least provides me with the opportunity to write this blog post .How cargo msrv works
I described the "support" from "minimal supported Rust version" (MSRV) above as the somewhat simplified "does compile with a Rust toolchain of a certain version".
You may write that as a function like so:
fn is_compatible(version) -> bool. If you run this test for some Rust version, when the function produces the valuetrue, then we consider the Rust version to be supported. If instead the function produces the valuefalse, then the Rust version is not supported.
cargo msrvspecifically searches for the minimal Rust version which is supported by a given Rust project. While there are some caveats, we build upon Rust's stability promise . In our case that is the idea that Rust versions are backwards compatible.For a simple example to determine an MSRV, you can linearly walk backwards from the most recent Rust version to the earliest. When your project doesn't compile for a specific Rust version, then the last version that did compile can be considered your MSRV.
Let's make it a bit more concrete with an example. For this example, we assume that Rust the following Rust versions exist:
1.0.0up to and including1.5.0.Consider a project which uses the Duration API which was stabilised by Rust 1.3.0 (and nothing more recent ).
Then, if you would compile this project with Rust version from most recent to least recent, you would expect the following to happen:
is_compatible(Rust 1.5.0)returnstrue✅is_compatible(Rust 1.4.0)returnstrue✅is_compatible(Rust 1.3.0)returnstrue✅is_compatible(Rust 1.2.0)returnsfalse❌ ("Duration is not stable")is_compatible(Rust 1.1.0)returnsfalse❌is_compatible(Rust 1.0.0)returnsfalse❌Since we only care about the minimal Rust version, you could have stopped searching after compiling Rust 1.2.0; Rust 1.3.0 was the earliest released Rust version which worked.
In reality doing a linear search is quite slow (at the time of writing, there are 79 minor versions), so we primarily use a binary search instead to incrementally reduce the search space.
cargo msrv verifyworks quite similar to "finding the MSRV", but instead of running a search which produces as primary output the MSRV, in this case the MSRV is already known in advance. So given aMSRVof1.3.0we just run theis_compatible(Rust 1.3.0)function once. If it returnstruewe can say that the 1.3.0 is an acceptable MSRV ( although not necessarily strictly so). More importantly, if it returns false, then the specified version is actually not supported, and thus can not be an MSRV).
⌘ preview - prerequisites - install - usage - JSON output format - a short history - license
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
No open issues yet, or sync has not completed.