Skip to main content

euv_cli/builder/android/
impl.rs

1use super::*;
2
3/// Behavioral metadata helpers for `AndroidTargetKind`.
4impl AndroidTargetKind {
5    /// Returns the lowercase target kind label (`"phone"` or `"wearos"`).
6    ///
7    /// # Returns
8    ///
9    /// - `&'static str` - Canonical lowercase kind label.
10    #[must_use]
11    pub fn as_label(&self) -> &'static str {
12        match self {
13            Self::Phone => ANDROID_KIND_PHONE,
14            Self::WearOs => ANDROID_KIND_WEAROS,
15        }
16    }
17
18    /// Returns whether this target builds a Wear OS smartwatch host.
19    ///
20    /// # Returns
21    ///
22    /// - `bool` - `true` for `WearOs`, `false` for `Phone`.
23    #[must_use]
24    pub fn is_wearos(&self) -> bool {
25        matches!(self, Self::WearOs)
26    }
27
28    /// Returns the Rust `PlatformKind` constant expression written to `host_config.rs`.
29    ///
30    /// # Returns
31    ///
32    /// - `&'static str` - `PlatformKind::Android` or `PlatformKind::Wearable`.
33    #[must_use]
34    pub fn platform_kind_expr(&self) -> &'static str {
35        match self {
36            Self::Phone => ANDROID_PLATFORM_EXPR_PHONE,
37            Self::WearOs => ANDROID_PLATFORM_EXPR_WEAROS,
38        }
39    }
40
41    /// Returns the default launcher application label.
42    ///
43    /// # Returns
44    ///
45    /// - `&'static str` - Default display label for the APK.
46    #[must_use]
47    pub fn default_app_label(&self) -> &'static str {
48        match self {
49            Self::Phone => ANDROID_PHONE_APP_LABEL,
50            Self::WearOs => ANDROID_WEAROS_APP_LABEL,
51        }
52    }
53
54    /// Returns the default APK filename inside the distribution output directory.
55    ///
56    /// # Returns
57    ///
58    /// - `&'static str` - `EuvShowcase.apk` or `EuvShowcaseWearOS.apk`.
59    #[must_use]
60    pub fn default_apk_name(&self) -> &'static str {
61        match self {
62            Self::Phone => ANDROID_PHONE_APK_NAME,
63            Self::WearOs => ANDROID_WEAROS_APK_NAME,
64        }
65    }
66
67    /// Returns the default subdirectory name under `dist/`.
68    ///
69    /// # Returns
70    ///
71    /// - `&'static str` - `"android"` or `"wearos"`.
72    #[must_use]
73    pub fn default_out_subdir(&self) -> &'static str {
74        match self {
75            Self::Phone => ANDROID_OUT_SUBDIR_PHONE,
76            Self::WearOs => ANDROID_OUT_SUBDIR_WEAROS,
77        }
78    }
79
80    /// Returns the staging directory name under `target/mobile-hosts/`.
81    ///
82    /// # Returns
83    ///
84    /// - `&'static str` - `"android-host"` or `"wearos-host"`.
85    #[must_use]
86    pub fn host_dir_name(&self) -> &'static str {
87        match self {
88            Self::Phone => ANDROID_HOST_DIR_PHONE,
89            Self::WearOs => ANDROID_HOST_DIR_WEAROS,
90        }
91    }
92
93    /// Returns the default Android Virtual Device name for emulator auto-boot.
94    ///
95    /// # Returns
96    ///
97    /// - `&'static str` - Default AVD name.
98    #[must_use]
99    pub fn default_avd_name(&self) -> &'static str {
100        match self {
101            Self::Phone => ANDROID_DEFAULT_PHONE_AVD,
102            Self::WearOs => ANDROID_DEFAULT_WEAROS_AVD,
103        }
104    }
105}
106
107/// Toolchain mapping helpers for `AndroidAbi`.
108impl AndroidAbi {
109    /// Returns the Android APK `lib/<abi>` directory name.
110    ///
111    /// # Returns
112    ///
113    /// - `&'static str` - Android ABI directory name.
114    #[must_use]
115    pub fn as_abi_dir(&self) -> &'static str {
116        match self {
117            Self::Arm64V8a => ANDROID_ABI_ARM64,
118            Self::ArmeabiV7a => ANDROID_ABI_ARMV7,
119            Self::X86_64 => ANDROID_ABI_X86_64,
120        }
121    }
122
123    /// Returns the corresponding Rust compilation target triple.
124    ///
125    /// # Returns
126    ///
127    /// - `&'static str` - Rust target triple.
128    #[must_use]
129    pub fn rust_triple(&self) -> &'static str {
130        match self {
131            Self::Arm64V8a => ANDROID_TRIPLE_ARM64,
132            Self::ArmeabiV7a => ANDROID_TRIPLE_ARMV7,
133            Self::X86_64 => ANDROID_TRIPLE_X86_64,
134        }
135    }
136
137    /// Returns the Android NDK clang executable prefix prior to `<api>-clang`.
138    ///
139    /// # Returns
140    ///
141    /// - `&'static str` - NDK clang target prefix.
142    #[must_use]
143    pub fn clang_prefix(&self) -> &'static str {
144        match self {
145            Self::Arm64V8a => ANDROID_CLANG_PREFIX_ARM64,
146            Self::ArmeabiV7a => ANDROID_CLANG_PREFIX_ARMV7,
147            Self::X86_64 => ANDROID_CLANG_PREFIX_X86_64,
148        }
149    }
150
151    /// Returns the underscore-delimited triple suffix used for `CC_<triple>` and `AR_<triple>`.
152    ///
153    /// # Returns
154    ///
155    /// - `&'static str` - Lowercase underscore triple key.
156    #[must_use]
157    pub fn cargo_env_triple(&self) -> &'static str {
158        match self {
159            Self::Arm64V8a => ANDROID_ENV_TRIPLE_ARM64,
160            Self::ArmeabiV7a => ANDROID_ENV_TRIPLE_ARMV7,
161            Self::X86_64 => ANDROID_ENV_TRIPLE_X86_64,
162        }
163    }
164
165    /// Returns the Cargo target linker environment variable name for this ABI.
166    ///
167    /// # Returns
168    ///
169    /// - `&'static str` - `CARGO_TARGET_<TRIPLE>_LINKER` variable name.
170    #[must_use]
171    pub fn cargo_linker_env(&self) -> &'static str {
172        match self {
173            Self::Arm64V8a => ANDROID_LINKER_ENV_ARM64,
174            Self::ArmeabiV7a => ANDROID_LINKER_ENV_ARMV7,
175            Self::X86_64 => ANDROID_LINKER_ENV_X86_64,
176        }
177    }
178}
179
180/// Default configuration builder for `AndroidBuildConfig`.
181impl Default for AndroidBuildConfig {
182    /// Creates a release `arm64-v8a` Android phone build configuration rooted at the current directory.
183    ///
184    /// # Returns
185    ///
186    /// - `Self` - Default `AndroidBuildConfig`.
187    fn default() -> Self {
188        Self {
189            workspace_root: PathBuf::from("."),
190            target_kind: AndroidTargetKind::Phone,
191            render_mode: RenderArg::Auto,
192            abis: vec![AndroidAbi::Arm64V8a],
193            app_version: None,
194            version_code: None,
195            package_id: ANDROID_DEFAULT_PACKAGE_ID.to_string(),
196            app_label: None,
197            out_file: None,
198            build_dir: None,
199            keystore_path: None,
200            keystore_pass: None,
201            key_pass: None,
202            key_alias: None,
203            release: true,
204            install: false,
205            shell_only: false,
206            api_level: None,
207            build_tools: None,
208            avd_name: None,
209        }
210    }
211}