File: build.rs

package info (click to toggle)
rust-maybe-uninit 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 140 kB
  • sloc: makefile: 4
file content (50 lines) | stat: -rw-r--r-- 1,067 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::env;
use std::process::Command;
use std::str::FromStr;

fn main() {
    let minor = match rustc_minor_version() {
        Some(minor) => minor,
        None => return,
    };
    if minor >= 22 {
        println!("cargo:rustc-cfg=derive_copy");
    }
    if minor >= 28 {
        println!("cargo:rustc-cfg=repr_transparent");
    }
    if minor >= 36 {
        println!("cargo:rustc-cfg=native_uninit");
    }

}

fn rustc_minor_version() -> Option<u32> {
    let rustc = env::var_os("RUSTC");

    let output = rustc.and_then(|rustc| {
        Command::new(rustc).arg("--version").output().ok()
    });

    let version = output.and_then(|output| {
        String::from_utf8(output.stdout).ok()
    });

    let version = if let Some(version) = version {
        version
    } else {
        return None;
    };

    let mut pieces = version.split('.');
    if pieces.next() != Some("rustc 1") {
        return None;
    }

    let next = match pieces.next() {
        Some(next) => next,
        None => return None,
    };

    u32::from_str(next).ok()
}