run_make_support/
targets.rs

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::panic;

use crate::command::Command;
use crate::env_var;
use crate::util::handle_failed_output;

/// `TARGET`
#[must_use]
pub fn target() -> String {
    env_var("TARGET")
}

/// Check if target is windows-like.
#[must_use]
pub fn is_windows() -> bool {
    target().contains("windows")
}

/// Check if target uses msvc.
#[must_use]
pub fn is_msvc() -> bool {
    target().contains("msvc")
}

/// Check if target uses macOS.
#[must_use]
pub fn is_darwin() -> bool {
    target().contains("darwin")
}

/// Check if target uses AIX.
#[must_use]
pub fn is_aix() -> bool {
    target().contains("aix")
}

/// Get the target OS on Apple operating systems.
#[must_use]
pub fn apple_os() -> &'static str {
    if target().contains("darwin") {
        "macos"
    } else if target().contains("ios") {
        "ios"
    } else if target().contains("tvos") {
        "tvos"
    } else if target().contains("watchos") {
        "watchos"
    } else if target().contains("visionos") {
        "visionos"
    } else {
        panic!("not an Apple OS")
    }
}

/// Check if `component` is within `LLVM_COMPONENTS`
#[must_use]
pub fn llvm_components_contain(component: &str) -> bool {
    // `LLVM_COMPONENTS` is a space-separated list of words
    env_var("LLVM_COMPONENTS").split_whitespace().find(|s| s == &component).is_some()
}

/// Run `uname`. This assumes that `uname` is available on the platform!
#[track_caller]
#[must_use]
pub fn uname() -> String {
    let caller = panic::Location::caller();
    let mut uname = Command::new("uname");
    let output = uname.run();
    if !output.status().success() {
        handle_failed_output(&uname, output, caller.line());
    }
    output.stdout_utf8()
}