run_make_support/
targets.rs
1use std::panic;
2
3use crate::command::Command;
4use crate::env_var;
5use crate::util::handle_failed_output;
6
7#[must_use]
9pub fn target() -> String {
10 env_var("TARGET")
11}
12
13#[must_use]
15pub fn is_windows() -> bool {
16 target().contains("windows")
17}
18
19#[must_use]
21pub fn is_msvc() -> bool {
22 target().contains("msvc")
23}
24
25#[must_use]
27pub fn is_windows_gnu() -> bool {
28 target().ends_with("windows-gnu")
29}
30
31#[must_use]
33pub fn is_darwin() -> bool {
34 target().contains("darwin")
35}
36
37#[must_use]
39pub fn is_aix() -> bool {
40 target().contains("aix")
41}
42
43#[must_use]
45pub fn apple_os() -> &'static str {
46 if target().contains("darwin") {
47 "macos"
48 } else if target().contains("ios") {
49 "ios"
50 } else if target().contains("tvos") {
51 "tvos"
52 } else if target().contains("watchos") {
53 "watchos"
54 } else if target().contains("visionos") {
55 "visionos"
56 } else {
57 panic!("not an Apple OS")
58 }
59}
60
61#[must_use]
63pub fn llvm_components_contain(component: &str) -> bool {
64 env_var("LLVM_COMPONENTS").split_whitespace().find(|s| s == &component).is_some()
66}
67
68#[track_caller]
70#[must_use]
71pub fn uname() -> String {
72 let caller = panic::Location::caller();
73 let mut uname = Command::new("uname");
74 let output = uname.run();
75 if !output.status().success() {
76 handle_failed_output(&uname, output, caller.line());
77 }
78 output.stdout_utf8()
79}