From a2ef9421e0dff27e966fc29fe317cd47f0874d72 Mon Sep 17 00:00:00 2001 From: Paddi Date: Sat, 13 Jul 2024 00:44:40 +0200 Subject: [PATCH] Determine rust channel by parsing rustc output The RUSTUP_TOOLCHAIN environment variable might not always be present. This is the case for e.g. NixOS where rust is routinely not installed via rustup, thus not setting this env var, causing build failures. Instead, build.rs will now run `rustc -V` and check if the output contains the word "nightly". --- azalea/build.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/azalea/build.rs b/azalea/build.rs index f97dce653..b661466ac 100644 --- a/azalea/build.rs +++ b/azalea/build.rs @@ -1,8 +1,12 @@ -use std::env; +use std::process::Command; fn main() { - let rust_toolchain = env::var("RUSTUP_TOOLCHAIN").unwrap(); - if rust_toolchain.starts_with("stable") { - panic!("Azalea currently requires nightly Rust. You can use `rustup override set nightly` to set the toolchain for this directory."); + let rustc_version_output = Command::new("rustc").arg("-V").output().unwrap(); + if !rustc_version_output.status.success() + || !String::from_utf8(rustc_version_output.stdout) + .unwrap() + .contains("nightly") + { + panic!("Azalea currently requires nightly Rust. If you have installed Rust with rustup you can use `rustup override set nightly` to set the toolchain for this directory."); } }