qlora-paste 1.0.17

Macros for all your token pasting needs (maintained fork)
Documentation
// Copyright 2019 David Tolnay
// Copyright 2024 Tyler Zervas
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::env;
use std::process::Command;
use std::str;

fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    let version = match rustc_version() {
        Some(version) => version,
        None => return,
    };

    if version.minor >= 80 {
        println!("cargo:rustc-check-cfg=cfg(no_literal_fromstr)");
        println!("cargo:rustc-check-cfg=cfg(feature, values(\"protocol_feature_paste\"))");
    }

    if version.minor < 54 {
        // https://github.com/rust-lang/rust/pull/84717
        println!("cargo:rustc-cfg=no_literal_fromstr");
    }
}

struct RustcVersion {
    minor: u32,
}

fn rustc_version() -> Option<RustcVersion> {
    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;
    }
    let minor = pieces.next()?.parse().ok()?;
    Some(RustcVersion { minor })
}