aboutsummaryrefslogtreecommitdiff
path: root/azalea/build.rs
blob: faed1365e16cb299f90be3d708110b5c130bfefd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::{env, process::Command};

fn main() {
    // If using `rustup`, check the toolchain via `RUSTUP_TOOLCHAIN`
    if let Ok(toolchain) = env::var("RUSTUP_TOOLCHAIN") {
        if toolchain.contains("nightly") {
            return;
        } else {
            panic!(
                "Azalea currently requires nightly Rust. You can run `rustup override set nightly` to set the toolchain for this directory."
            );
        }
    }

    // Get the path to the Rust compiler, defaulting to `rustc`
    let rustc_path = env::var("RUSTC")
        .or_else(|_| env::var("CARGO_BUILD_RUSTC"))
        .unwrap_or(String::from("rustc"));

    // Run `rustc -V` to check the toolchain version
    let rustc_command = Command::new(&rustc_path).arg("-V").output().unwrap();

    if rustc_command.status.success() {
        let rustc_output = String::from_utf8(rustc_command.stdout).unwrap();
        if !rustc_output.contains("nightly") {
            panic!(
                "Azalea currently requires nightly Rust. Please check the documentation for your installation method and ensure you are using the nightly toolchain."
            );
        }
    } else {
        let rustc_output = String::from_utf8(rustc_command.stderr).unwrap();
        panic!("Failed to run `{rustc_path} -V` to check the toolchain version, {rustc_output}");
    }
}