2017-01-15 09:16:47 +00:00
|
|
|
//! This tiny build script ensures that rocket is not compiled with an
|
|
|
|
//! incompatible version of rust.
|
|
|
|
|
2017-06-02 04:44:31 +00:00
|
|
|
extern crate yansi;
|
2017-01-15 09:16:47 +00:00
|
|
|
extern crate version_check;
|
|
|
|
|
2017-06-02 04:44:31 +00:00
|
|
|
use yansi::Color::{Red, Yellow, Blue, White};
|
2017-06-20 05:58:31 +00:00
|
|
|
use version_check::{supports_features, is_min_version, is_min_date};
|
2017-01-15 09:16:47 +00:00
|
|
|
|
|
|
|
// Specifies the minimum nightly version needed to compile Rocket.
|
2018-10-06 04:56:46 +00:00
|
|
|
const MIN_DATE: &'static str = "2018-10-05";
|
|
|
|
const MIN_VERSION: &'static str = "1.31.0-nightly";
|
2017-01-15 09:16:47 +00:00
|
|
|
|
|
|
|
fn main() {
|
2017-06-20 05:58:31 +00:00
|
|
|
let ok_channel = supports_features();
|
|
|
|
let ok_version = is_min_version(MIN_VERSION);
|
|
|
|
let ok_date = is_min_date(MIN_DATE);
|
|
|
|
let triple = (ok_channel, ok_version, ok_date);
|
|
|
|
|
|
|
|
let print_version_err = |version: &str, date: &str| {
|
2017-07-03 09:59:47 +00:00
|
|
|
eprintln!("{} {}. {} {}.",
|
2017-01-15 09:16:47 +00:00
|
|
|
White.paint("Installed version is:"),
|
2017-06-20 05:58:31 +00:00
|
|
|
Yellow.paint(format!("{} ({})", version, date)),
|
2017-01-15 09:16:47 +00:00
|
|
|
White.paint("Minimum required:"),
|
2017-06-20 05:58:31 +00:00
|
|
|
Yellow.paint(format!("{} ({})", MIN_VERSION, MIN_DATE)));
|
2017-01-15 09:16:47 +00:00
|
|
|
};
|
|
|
|
|
2017-06-20 05:58:31 +00:00
|
|
|
if let (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) = triple {
|
2017-06-03 00:41:15 +00:00
|
|
|
if !ok_channel {
|
2017-07-03 09:59:47 +00:00
|
|
|
eprintln!("{} {}",
|
2017-06-02 04:44:31 +00:00
|
|
|
Red.paint("Error:").bold(),
|
2017-06-03 00:41:15 +00:00
|
|
|
White.paint("Rocket requires a nightly or dev version of Rust."));
|
2017-06-20 05:58:31 +00:00
|
|
|
print_version_err(&*version, &*date);
|
2017-07-03 09:59:47 +00:00
|
|
|
eprintln!("{}{}{}",
|
2017-01-15 09:16:47 +00:00
|
|
|
Blue.paint("See the getting started guide ("),
|
2018-10-27 04:20:12 +00:00
|
|
|
White.paint("https://rocket.rs/v0.4/guide/getting-started/"),
|
2017-01-15 09:16:47 +00:00
|
|
|
Blue.paint(") for more information."));
|
|
|
|
panic!("Aborting compilation due to incompatible compiler.")
|
|
|
|
}
|
|
|
|
|
2017-06-20 05:58:31 +00:00
|
|
|
if !ok_version || !ok_date {
|
2017-07-03 09:59:47 +00:00
|
|
|
eprintln!("{} {}",
|
2017-06-02 04:44:31 +00:00
|
|
|
Red.paint("Error:").bold(),
|
2017-06-20 05:58:31 +00:00
|
|
|
White.paint("Rocket requires a more recent version of rustc."));
|
2017-07-03 09:59:47 +00:00
|
|
|
eprintln!("{}{}{}",
|
2017-01-15 09:16:47 +00:00
|
|
|
Blue.paint("Use `"),
|
|
|
|
White.paint("rustup update"),
|
|
|
|
Blue.paint("` or your preferred method to update Rust."));
|
2017-06-20 05:58:31 +00:00
|
|
|
print_version_err(&*version, &*date);
|
2017-01-15 09:16:47 +00:00
|
|
|
panic!("Aborting compilation due to incompatible compiler.")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("cargo:warning={}", "Rocket was unable to check rustc compatibility.");
|
|
|
|
println!("cargo:warning={}", "Build may fail due to incompatible rustc version.");
|
|
|
|
}
|
|
|
|
}
|