Debian Codegraph @

debian/rust-vendor/cc/src/target/apple.rs

raw
1 use super::TargetInfo;
2
3 impl TargetInfo<'_> {
4 pub(crate) fn apple_sdk_name(&self) -> &'static str {
5 match (self.os, self.env) {
6 // The target_env variable, as written here:
7 // https://doc.rust-lang.org/reference/conditional-compilation.html#target_env
8 // is only really used for disambiguation, so we use a "default" case instead of
9 // checking for a blank string.
10 ("macos", _) => "macosx",
11 ("ios", "sim") => "iphonesimulator",
12 ("ios", "macabi") => "macosx",
13 ("ios", _) => "iphoneos",
14 ("tvos", "sim") => "appletvsimulator",
15 ("tvos", _) => "appletvos",
16 ("watchos", "sim") => "watchsimulator",
17 ("watchos", _) => "watchos",
18 ("visionos", "sim") => "xrsimulator",
19 ("visionos", _) => "xros",
20 (os, _) => panic!("invalid Apple target OS {}", os),
21 }
22 }
23
24 pub(crate) fn apple_version_flag(&self, min_version: &str) -> String {
25 // There are many aliases for these, and `-mtargetos=` is preferred on Clang nowadays, but
26 // for compatibility with older Clang, we use the earliest supported name here.
27 //
28 // NOTE: GCC does not support `-miphoneos-version-min=` etc. (because it does not support
29 // iOS in general), but we specify them anyhow in case we actually have a Clang-like
30 // compiler disguised as a GNU-like compiler, or in case GCC adds support for these in the
31 // future.
32 //
33 // See also:
34 // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mmacos-version-min
35 // https://clang.llvm.org/docs/AttributeReference.html#availability
36 // https://gcc.gnu.org/onlinedocs/gcc/Darwin-Options.html#index-mmacosx-version-min
37 match (self.os, self.env) {
38 // The target_env variable, as written here:
39 // https://doc.rust-lang.org/reference/conditional-compilation.html#target_env
40 // is only really used for disambiguation, so we use a "default" case instead of
41 // checking for a blank string.
42 ("macos", _) => format!("-mmacosx-version-min={min_version}"),
43 ("ios", "sim") => format!("-mios-simulator-version-min={min_version}"),
44 ("ios", "macabi") => format!("-mtargetos=ios{min_version}-macabi"),
45 ("ios", _) => format!("-miphoneos-version-min={min_version}"),
46 ("tvos", "sim") => format!("-mappletvsimulator-version-min={min_version}"),
47 ("tvos", _) => format!("-mappletvos-version-min={min_version}"),
48 ("watchos", "sim") => format!("-mwatchsimulator-version-min={min_version}"),
49 ("watchos", _) => format!("-mwatchos-version-min={min_version}"),
50 // `-mxros-version-min` does not exist
51 // https://github.com/llvm/llvm-project/issues/88271
52 ("visionos", "sim") => format!("-mtargetos=xros{min_version}-simulator"),
53 ("visionos", _) => format!("-mtargetos=xros{min_version}"),
54 (os, _) => panic!("invalid Apple target OS {}", os),
55 }
56 }
57 }