2016-12-30 06:22:05 +00:00
|
|
|
//! This tiny build script ensures that rocket_codegen is not compiled with an
|
2017-01-15 09:16:47 +00:00
|
|
|
//! incompatible version of rust.
|
2016-12-30 06:22:05 +00:00
|
|
|
|
2017-06-02 04:44:31 +00:00
|
|
|
extern crate yansi;
|
2017-01-15 09:16:47 +00:00
|
|
|
extern crate version_check;
|
2016-12-30 06:22:05 +00:00
|
|
|
|
2017-06-02 04:44:31 +00:00
|
|
|
use yansi::Color::{Red, Yellow, Blue, White};
|
2017-06-03 00:41:15 +00:00
|
|
|
use version_check::{supports_features, is_min_version, is_min_date};
|
2016-12-30 06:22:05 +00:00
|
|
|
|
|
|
|
// Specifies the minimum nightly version needed to compile Rocket's codegen.
|
2017-06-02 04:59:40 +00:00
|
|
|
const MIN_DATE: &'static str = "2017-06-01";
|
2017-05-27 03:06:01 +00:00
|
|
|
const MIN_VERSION: &'static str = "1.19.0-nightly";
|
2016-12-30 06:22:05 +00:00
|
|
|
|
|
|
|
// Convenience macro for writing to stderr.
|
|
|
|
macro_rules! printerr {
|
|
|
|
($($arg:tt)*) => ({
|
|
|
|
use std::io::prelude::*;
|
|
|
|
write!(&mut ::std::io::stderr(), "{}\n", format_args!($($arg)*))
|
|
|
|
.expect("Failed to write to stderr.")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2017-06-03 00:41:15 +00:00
|
|
|
let ok_channel = supports_features();
|
2017-01-15 09:16:47 +00:00
|
|
|
let ok_version = is_min_version(MIN_VERSION);
|
|
|
|
let ok_date = is_min_date(MIN_DATE);
|
|
|
|
|
|
|
|
let print_version_err = |version: &str, date: &str| {
|
|
|
|
printerr!("{} {}. {} {}.",
|
|
|
|
White.paint("Installed version is:"),
|
|
|
|
Yellow.paint(format!("{} ({})", version, date)),
|
|
|
|
White.paint("Minimum required:"),
|
|
|
|
Yellow.paint(format!("{} ({})", MIN_VERSION, MIN_DATE)));
|
|
|
|
};
|
2016-12-30 06:22:05 +00:00
|
|
|
|
2017-06-03 00:41:15 +00:00
|
|
|
match (ok_channel, ok_version, ok_date) {
|
|
|
|
(Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => {
|
|
|
|
if !ok_channel {
|
2016-12-30 06:22:05 +00:00
|
|
|
printerr!("{} {}",
|
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-01-15 09:16:47 +00:00
|
|
|
print_version_err(&*version, &*date);
|
|
|
|
printerr!("{}{}{}",
|
|
|
|
Blue.paint("See the getting started guide ("),
|
|
|
|
White.paint("https://rocket.rs/guide/getting-started/"),
|
|
|
|
Blue.paint(") for more information."));
|
|
|
|
panic!("Aborting compilation due to incompatible compiler.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok_version || !ok_date {
|
|
|
|
printerr!("{} {}",
|
2017-06-02 04:44:31 +00:00
|
|
|
Red.paint("Error:").bold(),
|
2017-01-15 09:16:47 +00:00
|
|
|
White.paint("Rocket codegen requires a more recent version of rustc."));
|
2016-12-30 06:22:05 +00:00
|
|
|
printerr!("{}{}{}",
|
|
|
|
Blue.paint("Use `"),
|
|
|
|
White.paint("rustup update"),
|
|
|
|
Blue.paint("` or your preferred method to update Rust."));
|
2017-01-15 09:16:47 +00:00
|
|
|
print_version_err(&*version, &*date);
|
2016-12-30 06:22:05 +00:00
|
|
|
panic!("Aborting compilation due to incompatible compiler.")
|
|
|
|
}
|
2017-01-15 09:16:47 +00:00
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
println!("cargo:warning={}", "Rocket was unable to check rustc compatibility.");
|
|
|
|
println!("cargo:warning={}", "Build may fail due to incompatible rustc version.");
|
2016-12-30 06:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|