mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 07:58:04 +00:00
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
use std::env;
|
|
use std::process::Command;
|
|
use std::str;
|
|
|
|
// The rustc-cfg strings below are *not* public API. Please let us know by
|
|
// opening a GitHub issue if your build environment requires some way to enable
|
|
// these cfgs other than by executing our build script.
|
|
fn main() {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
let minor = match rustc_minor_version() {
|
|
Some(minor) => minor,
|
|
None => return,
|
|
};
|
|
|
|
if minor >= 77 {
|
|
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
|
|
println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");
|
|
}
|
|
|
|
// Current minimum supported version of serde_derive crate is Rust 1.61.
|
|
if minor < 61 {
|
|
println!("cargo:rustc-cfg=no_serde_derive");
|
|
}
|
|
|
|
// Support for the `#[diagnostic]` tool attribute namespace
|
|
// https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#diagnostic-attributes
|
|
if minor < 78 {
|
|
println!("cargo:rustc-cfg=no_diagnostic_namespace");
|
|
}
|
|
}
|
|
|
|
fn rustc_minor_version() -> Option<u32> {
|
|
let rustc = env::var_os("RUSTC")?;
|
|
let output = Command::new(rustc).arg("--version").output().ok()?;
|
|
let version = str::from_utf8(&output.stdout).ok()?;
|
|
let mut pieces = version.split('.');
|
|
if pieces.next() != Some("rustc 1") {
|
|
return None;
|
|
}
|
|
pieces.next()?.parse().ok()
|
|
}
|