Skip to main content

euv_cli/builder/apple/
impl.rs

1use super::*;
2
3/// Target metadata helpers for `AppleTargetKind`.
4impl AppleTargetKind {
5    /// Returns the canonical CLI label for this Apple target.
6    ///
7    /// # Returns
8    ///
9    /// - `&'static str` - Target label string.
10    #[must_use]
11    pub fn as_label(&self) -> &'static str {
12        match self {
13            Self::IosSim => APPLE_LABEL_IOS_SIM,
14            Self::IpadSim => APPLE_LABEL_IPAD_SIM,
15            Self::IosDevice => APPLE_LABEL_IOS_DEVICE,
16            Self::IpadDevice => APPLE_LABEL_IPAD_DEVICE,
17            Self::WatchOsSim => APPLE_LABEL_WATCHOS_SIM,
18            Self::WatchOsDevice => APPLE_LABEL_WATCHOS_DEVICE,
19        }
20    }
21
22    /// Returns the Rust target triple for compiling the static library.
23    ///
24    /// # Returns
25    ///
26    /// - `&'static str` - Rust compiler target triple.
27    #[must_use]
28    pub fn rust_triple(&self) -> &'static str {
29        match self {
30            Self::IosSim | Self::IpadSim => APPLE_TRIPLE_IOS_SIM,
31            Self::IosDevice | Self::IpadDevice => APPLE_TRIPLE_IOS_DEVICE,
32            Self::WatchOsSim => APPLE_TRIPLE_WATCHOS_SIM,
33            Self::WatchOsDevice => APPLE_TRIPLE_WATCHOS_DEVICE,
34        }
35    }
36
37    /// Returns the Xcode `--sdk` name required to compile and link this target.
38    ///
39    /// # Returns
40    ///
41    /// - `&'static str` - Xcode SDK identifier.
42    #[must_use]
43    pub fn xcode_sdk(&self) -> &'static str {
44        match self {
45            Self::IosSim | Self::IpadSim => APPLE_SDK_IPHONE_SIM,
46            Self::IosDevice | Self::IpadDevice => APPLE_SDK_IPHONE_OS,
47            Self::WatchOsSim => APPLE_SDK_WATCH_SIM,
48            Self::WatchOsDevice => APPLE_SDK_WATCH_OS,
49        }
50    }
51
52    /// Returns whether this target runs inside an Apple Simulator.
53    ///
54    /// # Returns
55    ///
56    /// - `bool` - `true` for simulator targets.
57    #[must_use]
58    pub fn is_simulator(&self) -> bool {
59        matches!(self, Self::IosSim | Self::IpadSim | Self::WatchOsSim)
60    }
61
62    /// Returns whether this target builds an Apple watchOS SwiftUI bundle.
63    ///
64    /// # Returns
65    ///
66    /// - `bool` - `true` for watchOS targets.
67    #[must_use]
68    pub fn is_watchos(&self) -> bool {
69        matches!(self, Self::WatchOsSim | Self::WatchOsDevice)
70    }
71
72    /// Returns whether this target prefers an iPad simulator device.
73    ///
74    /// # Returns
75    ///
76    /// - `bool` - `true` for iPadOS targets.
77    #[must_use]
78    pub fn is_ipad(&self) -> bool {
79        matches!(self, Self::IpadSim | Self::IpadDevice)
80    }
81
82    /// Returns the `.app` bundle directory name.
83    ///
84    /// # Returns
85    ///
86    /// - `&'static str` - `EuvShowcase.app` or `EuvWatch.app`.
87    #[must_use]
88    pub fn default_bundle_name(&self) -> &'static str {
89        if self.is_watchos() {
90            APPLE_WATCHOS_BUNDLE_NAME
91        } else {
92            APPLE_IOS_BUNDLE_NAME
93        }
94    }
95
96    /// Returns the executable binary filename inside the `.app` bundle.
97    ///
98    /// # Returns
99    ///
100    /// - `&'static str` - `EuvShowcase` or `EuvWatch`.
101    #[must_use]
102    pub fn default_executable_name(&self) -> &'static str {
103        if self.is_watchos() {
104            APPLE_WATCHOS_EXEC_NAME
105        } else {
106            APPLE_IOS_EXEC_NAME
107        }
108    }
109
110    /// Returns the default `CFBundleIdentifier`.
111    ///
112    /// # Returns
113    ///
114    /// - `&'static str` - Default bundle identifier string.
115    #[must_use]
116    pub fn default_bundle_id(&self) -> &'static str {
117        if self.is_watchos() {
118            APPLE_WATCHOS_BUNDLE_ID
119        } else {
120            APPLE_IOS_BUNDLE_ID
121        }
122    }
123
124    /// Returns the default relative output directory under `dist/`.
125    ///
126    /// # Returns
127    ///
128    /// - `&'static str` - `"ios"` or `"wearable/watchos"`.
129    #[must_use]
130    pub fn default_out_subdir(&self) -> &'static str {
131        if self.is_watchos() {
132            APPLE_OUT_SUBDIR_WATCHOS
133        } else {
134            APPLE_OUT_SUBDIR_IOS
135        }
136    }
137
138    /// Returns the staging directory name under `target/mobile-hosts/`.
139    ///
140    /// # Returns
141    ///
142    /// - `&'static str` - `"ios-host"` or `"watchos-host"`.
143    #[must_use]
144    pub fn host_dir_name(&self) -> &'static str {
145        if self.is_watchos() {
146            APPLE_HOST_DIR_WATCHOS
147        } else {
148            APPLE_HOST_DIR_IOS
149        }
150    }
151}
152
153/// Default configuration builder for `AppleBuildConfig`.
154impl Default for AppleBuildConfig {
155    /// Creates a release hardware-rendered iOS Simulator build configuration rooted at `.`.
156    ///
157    /// # Returns
158    ///
159    /// - `Self` - Default `AppleBuildConfig`.
160    fn default() -> Self {
161        Self {
162            workspace_root: PathBuf::from("."),
163            target_kind: AppleTargetKind::IosSim,
164            render_mode: RenderArg::Hardware,
165            app_version: None,
166            build_number: None,
167            bundle_id: None,
168            out_dir: None,
169            build_dir: None,
170            archive_path: None,
171            codesign_identity: None,
172            sim_udid: None,
173            release: true,
174            no_launch: false,
175            shell_only: false,
176        }
177    }
178}