run_make_support/targets.rs
1use std::panic;
2
3use crate::command::Command;
4use crate::env_var;
5
6/// `TARGET`
7#[must_use]
8pub fn target() -> String {
9 env_var("TARGET")
10}
11
12/// Check if target is windows-like.
13#[must_use]
14pub fn is_windows() -> bool {
15 target().contains("windows")
16}
17
18/// Check if target is windows-msvc.
19#[must_use]
20pub fn is_windows_msvc() -> bool {
21 target().ends_with("windows-msvc")
22}
23
24/// Check if target is windows-gnu.
25#[must_use]
26pub fn is_windows_gnu() -> bool {
27 target().ends_with("windows-gnu")
28}
29
30/// Check if target is win7.
31#[must_use]
32pub fn is_win7() -> bool {
33 target().contains("win7")
34}
35
36/// Check if target uses macOS.
37#[must_use]
38pub fn is_darwin() -> bool {
39 target().contains("darwin")
40}
41
42/// Check if target uses AIX.
43#[must_use]
44pub fn is_aix() -> bool {
45 target().contains("aix")
46}
47
48/// Check if target is arm64ec.
49#[must_use]
50pub fn is_arm64ec() -> bool {
51 target().starts_with("arm64ec")
52}
53
54/// Get the target OS on Apple operating systems.
55#[must_use]
56pub fn apple_os() -> &'static str {
57 if target().contains("darwin") {
58 "macos"
59 } else if target().contains("ios") {
60 "ios"
61 } else if target().contains("tvos") {
62 "tvos"
63 } else if target().contains("watchos") {
64 "watchos"
65 } else if target().contains("visionos") {
66 "visionos"
67 } else {
68 panic!("not an Apple OS")
69 }
70}
71
72/// Check if `component` is within `LLVM_COMPONENTS`
73#[must_use]
74pub fn llvm_components_contain(component: &str) -> bool {
75 // `LLVM_COMPONENTS` is a space-separated list of words
76 env_var("LLVM_COMPONENTS").split_whitespace().find(|s| s == &component).is_some()
77}
78
79/// Run `uname`. This assumes that `uname` is available on the platform!
80#[track_caller]
81#[must_use]
82pub fn uname() -> String {
83 Command::new("uname").run().stdout_utf8()
84}