aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol
diff options
context:
space:
mode:
authorEightFactorial <29801334+EightFactorial@users.noreply.github.com>2024-12-07 15:23:27 -0800
committerGitHub <noreply@github.com>2024-12-07 17:23:27 -0600
commit07109964ad8486a9d4caee430ccadf7f7fc3d648 (patch)
tree1ff5e99ecf2529d2c77a6e04dbe9f9dd0264e6c4 /azalea-protocol
parent39f4d68e1ff1f0fa0d45663335d83299d5d37790 (diff)
downloadazalea-drasl-07109964ad8486a9d4caee430ccadf7f7fc3d648.tar.xz
Emit a build warning if the compiler may fail to build (#194)
This should be reverted when the latest nightly can build again
Diffstat (limited to 'azalea-protocol')
-rw-r--r--azalea-protocol/build.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/azalea-protocol/build.rs b/azalea-protocol/build.rs
new file mode 100644
index 00000000..e3bb9c3c
--- /dev/null
+++ b/azalea-protocol/build.rs
@@ -0,0 +1,53 @@
+use std::env;
+use std::process::Command;
+
+/// The maximum recommended toolchain version, as a triple.
+const TOOLCHAIN_MAX: (u32, u32, u32) = (2024, 11, 11);
+
+fn main() {
+ if let Some(toolchain) = toolchain_version() {
+ // If the toolchain is not nightly, do nothing
+ if !toolchain.contains("nightly") {
+ return;
+ }
+
+ // Warn if the toolchain may cause issues
+ if !recommended_toolchain(&toolchain).unwrap_or_default() {
+ println!("cargo::warning=The current Rust version may cause issues, try using: \"nightly-{}-{}-{}\"", TOOLCHAIN_MAX.0, TOOLCHAIN_MAX.1, TOOLCHAIN_MAX.2);
+ }
+ }
+}
+
+/// Attempt to get the current toolchain version
+fn toolchain_version() -> Option<String> {
+ // Use the `RUSTUP_TOOLCHAIN` environment variable
+ if let Ok(toolchain) = env::var("RUSTUP_TOOLCHAIN") {
+ return Some(toolchain);
+ }
+
+ // Fallback to running `rustc -V`
+ let rustc_path = env::var("RUSTC")
+ .or_else(|_| env::var("CARGO_BUILD_RUSTC"))
+ .unwrap_or(String::from("rustc"));
+
+ let rustc_command = Command::new(&rustc_path).arg("-V").output().unwrap();
+ if rustc_command.status.success() {
+ String::from_utf8(rustc_command.stdout).ok()
+ } else {
+ None
+ }
+}
+
+
+/// Attempt to parse the version of the toolchain,
+/// returning `Some(true)` if the toolchain should be fine.
+fn recommended_toolchain(toolchain: &str) -> Option<bool> {
+ let mut split = toolchain.split('-');
+ while split.next() != Some("nightly") {}
+
+ let year = split.next()?.parse().ok()?;
+ let month = split.next()?.parse().ok()?;
+ let day = split.next()?.parse().ok()?;
+
+ Some((year, month, day) <= TOOLCHAIN_MAX)
+}