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