File: build.rs

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (57 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download | duplicates (22)
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
51
52
53
54
55
56
57
use std::{env, ffi::OsString, process::Command};

/// Tries to get the minor version of the Rust compiler in use.
/// If it fails for any reason, returns `None`.
///
/// Based on the `rustc_version` crate.
fn rustc_minor_version() -> Option<u64> {
    let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));
    let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()) {
        let mut cmd = Command::new(wrapper);
        cmd.arg(rustc);
        cmd
    } else {
        Command::new(rustc)
    };

    let out = cmd.arg("-vV").output().ok()?;

    if !out.status.success() {
        return None;
    }

    let stdout = std::str::from_utf8(&out.stdout).ok()?;

    // Assumes that the first line contains "rustc 1.xx.0-channel (abcdef 2025-01-01)"
    // where "xx" is the minor version which we want to extract
    let mut lines = stdout.lines();
    let first_line = lines.next()?;
    let minor_ver_str = first_line.split(".").nth(1)?;
    minor_ver_str.parse().ok()
}

fn main() {
    // Automatically detect cfg(sanitize = "memory") even if cfg(sanitize) isn't
    // supported. Build scripts get cfg() info, even if the cfg is unstable.
    println!("cargo:rerun-if-changed=build.rs");
    let santizers = std::env::var("CARGO_CFG_SANITIZE").unwrap_or_default();
    if santizers.contains("memory") {
        println!("cargo:rustc-cfg=getrandom_msan");
    }

    // Use `RtlGenRandom` on older compiler versions since win7 targets
    // TODO(MSRV 1.78): Remove this check
    let target_family = env::var_os("CARGO_CFG_TARGET_FAMILY").and_then(|f| f.into_string().ok());
    if target_family.as_deref() == Some("windows") {
        /// Minor version of the Rust compiler in which win7 targets were inroduced
        const WIN7_INTRODUCED_MINOR_VER: u64 = 78;

        match rustc_minor_version() {
            Some(minor_ver) if minor_ver < WIN7_INTRODUCED_MINOR_VER => {
                println!("cargo:rustc-cfg=getrandom_windows_legacy");
            }
            None => println!("cargo:warning=Couldn't detect minor version of the Rust compiler"),
            _ => {}
        }
    }
}