tl;dr how do I list the minimum rust version required for my project and dependencies?
In my rust project, each entry in Cargo.toml
section [dependencies]
may have some minimum rust version required. I want to list those version requirements per dependency. This is in order to understand the minimum rust version for the my rust project.
Of course, for each dependency, I could find it's Cargo.toml
and note any rust-version
entry. And then repeat that for each of it's dependencies. But that is a time-consuming manual process. I was hoping for a cargo
command or a tool that would effectively do this.
You can install and use cargo-msrv for that ("MSRV" means "minimum-supported Rust version"); it has multiple commands that can help.
For example cargo msrv list
will list the advertised Rust versions of your crate, its dependencies, and any transitive dependencies. Below is for an empty package with a chrono
dependency:
> cargo msrv list
Fetching index
┌────────┬───────────────────────────────────────────────────────────────────────────┐
│ MSRV ┆ Dependency │
╞════════╪═══════════════════════════════════════════════════════════════════════════╡
│ ┆ mycrate, chrono, winapi, wasm-bindgen, time, num-traits, num-integer, │
│ ┆ js-sys, iana-time-zone, winapi-x86_64-pc-windows-gnu, │
│ ┆ winapi-i686-pc-windows-gnu, wasm-bindgen-macro, cfg-if, wasi, libc, │
│ ┆ autocfg, iana-time-zone-haiku, core-foundation-sys, │
│ ┆ android_system_properties, wasm-bindgen-macro-support, │
│ ┆ wasm-bindgen-shared, wasm-bindgen-backend, codespan-reporting, cc, log, │
│ ┆ bumpalo, unicode-width, termcolor, winapi-util │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1.0.0 ┆ scratch │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1.31.0 ┆ quote, syn, proc-macro2, unicode-ident │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1.34.0 ┆ link-cplusplus │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1.48.0 ┆ cxx-build, cxx, cxxbridge-macro, cxxbridge-flags │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1.56.0 ┆ once_cell │
└────────┴───────────────────────────────────────────────────────────────────────────┘
You may notice though, that many crates do not have a rust-version
documented in their Cargo.toml. So you should be careful that, just because highest minimum reported is 1.56.0
, you don't mistake that for a guarantee that 1.57.0 (for example) will work.
For that, the basic cargo msrv
will install and check your crate with various versions of Rust to see whether it works or not:
> cargo msrv
Fetching index
Determining the Minimum Supported Rust Version (MSRV) for toolchain x86_64-unknown-linux-gnu
Using check command cargo check
Check for toolchain '1.60.0-x86_64-unknown-linux-gnu' succeeded
Check for toolchain '1.58.1-x86_64-unknown-linux-gnu' succeeded
Check for toolchain '1.57.0-x86_64-unknown-linux-gnu' succeeded
Check for toolchain '1.56.1-x86_64-unknown-linux-gnu' succeeded
Finished The MSRV is: 1.56.1