-
Notifications
You must be signed in to change notification settings - Fork 149
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Motivations
Sometimes libc upstream stuff broke in the past. If we upfront notice it and we need to make breaking changes and cut a new release that has a clear cut in it,we could make a last release on version x indicating the maximum supported rust version.
That would help people to do the right thing, either upgrade to the correct compiler version or to the correct esp-idf-* version
Solution
We can actually test with what compiler version we are currently building. Unfortunately its not directly passed to us via env variables but we could do the following in the build.rs :D
use std::env;
use std::process::Command;
fn main() {
// Get the exact rustc binary Cargo is using
let rustc_path = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
// Execute rustc to get the version
let output = Command::new(rustc_path)
.arg("--version")
.output()
.expect("Failed to execute rustc");
let rustc_output = String::from_utf8(output.stdout).expect("Invalid UTF-8 output");
// Extract version string (e.g., "rustc 1.78.0-nightly (abc123 2024-01-01)")
let raw_version = rustc_output
.split_whitespace()
.nth(1) // Get the second word (the version)
.unwrap_or("0.0.0");
// Remove "-nightly" or other suffixes if present
let clean_version = raw_version.split('-').next().unwrap_or("0.0.0");
// Convert to (major, minor, patch) tuple for comparison
let version_tuple = parse_version(clean_version);
// Define max supported version (1.85.0)
let max_version = (1, 85, 0);
if version_tuple > max_version {
panic!(
"Error: Detected Rust version {}. This crate version supports Rust 1.85.0 or lower. \
Please downgrade your Rust compiler or upgrade this crate.",
clean_version
);
}
println!(
"cargo:warning=Compiling with Rust version: {}",
clean_version
);
}
// Helper function to parse "1.78.0" into (1, 78, 0)
fn parse_version(version: &str) -> (u32, u32, u32) {
let mut parts = version.split('.').map(|s| s.parse::<u32>().unwrap_or(0));
(
parts.next().unwrap_or(0),
parts.next().unwrap_or(0),
parts.next().unwrap_or(0),
)
}In the end its only a thing to guide the people to the right stuff.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request