'Specify the version of rustc required for a Cargo project
Is it possible to specify that a Cargo project requires a minimum rustc version of, for example, 1.1.0 to compile?
Solution 1:[1]
If your project required a minimum rustc version of 1.1.0 to compile, you could simply create a file named rust-toolchain (without any file extension) in the same directory as your Cargo.toml file, and add the following contents to it:
[toolchain]
channel = "1.1.0"
components = ["rust-src"]
Then when you run cargo build it will automatically download and install that version and switch to it. See this Rust Blog post for further details.
This Rust RFC #2495 proposes an alternative approach in future where we may be able to just add the line rust = "1.1.0" to the Cargo.toml file.
Solution 2:[2]
I've found some old proposals on Github:
https://github.com/rust-lang/cargo/issues/837
https://github.com/rust-lang/cargo/issues/1044
https://github.com/rust-lang/cargo/issues/1214
They were closed with
I think that for now there's not a lot actionable in this ticket, I agree that we'll definitely want to re-evaluate post-1.0, but for now I don't think cargo is going to enter the business of supporting various Rust versions as it's just too unstable to track currently.
So there seems to be no way yet. Maybe you should raise your case there.
Solution 3:[3]
In Rust 1.56.0 you can use rust-version:
The rust-version field is an optional key that tells cargo what version of the Rust language and compiler your package can be compiled with. If the currently selected version of the Rust compiler is older than the stated version, cargo will exit with an error, telling the user what version is required.
[package]
rust-version = "1.56"
Solution 4:[4]
No.
As of right now, the only thing you can realistically do is note the required version in the documentation and/or the README for the crate.
You may be able to configure multirust to use the correct compiler, but keep in mind that it only works in UNIX-y environments.
Solution 5:[5]
If you use Travis, you can configure which versions of Rust, and which channels, you support. That's a common way to document it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Luke Schoen |
| Solution 2 | Veedrac |
| Solution 3 | Stargateur |
| Solution 4 | DK. |
| Solution 5 | Steve Klabnik |
