1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

Determine rust channel by parsing rustc output if env vars do not exist (#163)

* 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".

* Check env vars first, fall back to rustc in $PATH

* Try to check RUSTUP_TOOLCHAIN first
This commit is contained in:
Patrick 2024-07-19 23:28:40 +02:00 committed by GitHub
parent 3d717b63e5
commit 4ee0b784ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,8 +1,24 @@
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.");
match env::var("RUSTUP_TOOLCHAIN") {
Ok(rust_toolchain) if !rust_toolchain.starts_with("nightly") => { // stable & beta
panic!("Azalea currently requires nightly Rust. You can use `rustup override set nightly` to set the toolchain for this directory.");
}
Ok(_) => return, // nightly
Err(_) => { // probably not installed via rustup, run rustc and parse its output
let rustc_command = env::var("RUSTC")
.or_else(|_| env::var("CARGO_BUILD_RUSTC"))
.unwrap_or(String::from("rustc"));
let rustc_version_output = Command::new(rustc_command).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. It seems that you did not install Rust via rustup. Please check the documentation for your installation method, to find out how to use nightly Rust.");
}
}
}
}