cargo-msrv
Determine project's minimum Rust version
TLDR
Display the MSRVs of dependencies (as specified in their Cargo.toml)
Find the MSRV of the project by trying to compile it with various toolchains
Show the MSRV of the project as specified in Cargo.toml
Set the MSRV in Cargo.toml to a given Rust version
Verify whether the MSRV is satisfiable by compiling the project using the specified version of Rust
SYNOPSIS
cargo msrv [OPTIONS]
cargo msrv find [OPTIONS]
cargo msrv show [OPTIONS]
cargo msrv set <VERSION> [OPTIONS]
PARAMETERS
--min <VERSION>
Specifies the minimum Rust version to consider in the search range.
--max <VERSION>
Specifies the maximum Rust version to consider in the search range.
--path <PATH>
Path to the crate root directory to analyze. Defaults to the current directory.
--target <TRIPLE>
Specifies the target triple (e.g., x86_64-unknown-linux-gnu) for cross-compilation MSRV checks.
--workspace
Finds the MSRV for the entire workspace, rather than just the current crate.
--output-format <FORMAT>
Sets the output format for the MSRV result (e.g., human, json).
--check <COMMAND_NAME>
Specifies the cargo subcommand to run for testing compatibility (e.g., check, build, test).
--log-level <LEVEL>
Sets the verbosity of logging output (e.g., info, debug, trace).
-h, --help
Displays help information for the command or a specific subcommand.
-V, --version
Prints the version of the cargo-msrv tool.
DESCRIPTION
cargo-msrv is a cargo subcommand designed to automatically determine the lowest Rust compiler version that can successfully build a given Rust project. This tool is invaluable for library authors and application developers who need to define and adhere to a Minimum Supported Rust Version (MSRV) to ensure broad compatibility with their users' toolchains.
It operates by leveraging rustup to iteratively install and switch between various Rust toolchain versions, performing build or check operations for each. By analyzing the success or failure of these operations, cargo-msrv systematically identifies the MSRV. The process helps in maintaining compatibility in the rapidly evolving Rust ecosystem, preventing accidental MSRV bumps, and aiding in the integration of MSRV verification into Continuous Integration (CI) pipelines.
CAVEATS
Prerequisites: cargo-msrv heavily relies on rustup being installed and available on the system to manage Rust toolchains. Without rustup, it cannot function.
Execution Time: Determining the MSRV can be a time-consuming process, especially for projects with a wide range of potential Rust versions or complex dependency trees, as it involves downloading and compiling with multiple toolchains.
Network Dependency: The tool requires active network connectivity to download new Rust toolchains and release data via rustup.
<B>MSRV DEFINITION</B>
The Minimum Supported Rust Version (MSRV) is the oldest Rust toolchain version that a particular crate (library or application) is guaranteed to build and function correctly with. Specifying an MSRV helps crate users understand the minimum compiler version they need to use, ensuring compatibility and avoiding build failures.
<B>HOW IT WORKS</B>
cargo-msrv operates by systematically testing different Rust toolchains. It utilizes rustup to install and switch between various Rust versions. For each version, it attempts to run a specified cargo command (e.g., cargo check or cargo build). By tracking which versions succeed and which fail, it uses an efficient search strategy (typically bisecting) to pinpoint the lowest compatible Rust version.
<B>CI INTEGRATION</B>
Many Rust projects integrate cargo-msrv into their Continuous Integration (CI) workflows. This automation ensures that every code change is automatically checked against the declared MSRV, preventing accidental bumps or regressions. This proactive verification helps maintain compatibility and assures users that the crate adheres to its stated MSRV policy.
HISTORY
cargo-msrv emerged from the Rust community's growing need to automate the process of identifying and verifying the Minimum Supported Rust Version (MSRV) for crates. Before its development, MSRV checks were often manual, tedious, and prone to error, especially for libraries aiming for broad compatibility. The project gained traction as a crucial tool for library maintainers, providing an efficient, automated method to manage MSRV declarations and prevent regressions. It has seen continuous enhancements, including improved search strategies (like bisecting), better integration with workspace setups, and diverse output options tailored for CI/CD pipelines, solidifying its role in the modern Rust development workflow.


