Is it possible to specify that a Cargo project requires a minimum rustc version of, for example, 1.1.0 to compile?
You can use a build script like this
extern crate rustc_version;
use std::io::{self, Write};
use std::process::exit;
use rustc_version::version_matches;
fn main() {
if !version_matches(">= 1.1.0") {
writeln!(&mut io::stderr(), "This crate requires rustc >= 1.1.0.").unwrap();
exit(1);
}
}
This uses the rustc_version crate.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With