Rocket/contrib/codegen/build.rs

41 lines
1.6 KiB
Rust
Raw Normal View History

2019-05-24 08:47:49 +00:00
//! Ensures Rocket isn't compiled with an incompatible version of Rust.
2018-10-31 20:29:22 +00:00
extern crate yansi;
extern crate version_check;
2019-05-24 08:47:49 +00:00
use yansi::{Paint, Color::{Red, Yellow, Blue}};
2018-10-31 20:29:22 +00:00
// Specifies the minimum nightly version needed to compile Rocket.
const MIN_DATE: &'static str = "2018-10-05";
const MIN_VERSION: &'static str = "1.31.0-nightly";
2019-05-24 08:47:49 +00:00
macro_rules! err {
($version:expr, $date:expr, $msg:expr) => (
eprintln!("{} {}", Red.paint("Error:").bold(), Paint::new($msg).bold());
eprintln!("Installed version: {}", Yellow.paint(format!("{} ({})", $version, $date)));
eprintln!("Minimum required: {}", Yellow.paint(format!("{} ({})", MIN_VERSION, MIN_DATE)));
)
}
2018-10-31 20:29:22 +00:00
fn main() {
2019-05-24 08:47:49 +00:00
if let Some((version, channel, date)) = version_check::triple() {
if !channel.supports_features() {
err!(version, date, "Rocket requires a 'dev' or 'nightly' version of rustc.");
eprint!("{}", Blue.paint("See the getting started guide ("));
eprint!("https://rocket.rs/v0.5/guide/getting-started/");
eprintln!("{}", Blue.paint(") for more information."));
2018-10-31 20:29:22 +00:00
panic!("Aborting compilation due to incompatible compiler.")
}
2019-05-24 08:47:49 +00:00
if !version.at_least(MIN_VERSION) || !date.at_least(MIN_DATE) {
err!(version, date, "Rocket requires a more recent version of rustc.");
2018-10-31 20:29:22 +00:00
panic!("Aborting compilation due to incompatible compiler.")
}
} else {
2019-05-24 08:47:49 +00:00
println!("cargo:warning={}", "Rocket was unable to check rustc compiler compatibility.");
2018-10-31 20:29:22 +00:00
println!("cargo:warning={}", "Build may fail due to incompatible rustc version.");
}
}