Skip to main content

euv_cli/builder/ecosystem/
impl.rs

1use super::*;
2
3/// Form factor metadata helpers for `HarmonyDeviceKind`.
4impl HarmonyDeviceKind {
5    /// Returns the canonical lowercase form factor label (`phone`, `2in1`, `wearable`, etc.).
6    ///
7    /// # Returns
8    ///
9    /// - `&'static str` - Canonical HarmonyOS device label.
10    #[must_use]
11    pub fn as_label(&self) -> &'static str {
12        match self {
13            Self::Phone => HARMONY_DEVICE_PHONE,
14            Self::Tablet => HARMONY_DEVICE_TABLET,
15            Self::Pc2In1 => HARMONY_DEVICE_2IN1,
16            Self::Universal => HARMONY_DEVICE_UNIVERSAL,
17            Self::Foldable => HARMONY_DEVICE_FOLDABLE,
18            Self::Wearable => HARMONY_DEVICE_WEARABLE,
19            Self::Tv => HARMONY_DEVICE_TV,
20            Self::Car => HARMONY_DEVICE_CAR,
21        }
22    }
23
24    /// Returns the Rust `HarmonyDeviceType` constant expression written to `host_config.rs`.
25    ///
26    /// # Returns
27    ///
28    /// - `&'static str` - Rust enum expression.
29    #[must_use]
30    pub fn rust_device_expr(&self) -> &'static str {
31        match self {
32            Self::Phone => HARMONY_EXPR_PHONE,
33            Self::Tablet => HARMONY_EXPR_TABLET,
34            Self::Pc2In1 | Self::Universal => HARMONY_EXPR_PC_2IN1,
35            Self::Foldable => HARMONY_EXPR_FOLDABLE,
36            Self::Wearable => HARMONY_EXPR_WATCH,
37            Self::Tv => HARMONY_EXPR_TV,
38            Self::Car => HARMONY_EXPR_AUTOMOTIVE,
39        }
40    }
41
42    /// Returns whether this device profile defaults to dual-ABI (`arm64-v8a` + `x86_64`) compilation.
43    ///
44    /// # Returns
45    ///
46    /// - `bool` - `true` for `Pc2In1` and `Universal`.
47    #[must_use]
48    pub fn is_pc_target(&self) -> bool {
49        matches!(self, Self::Pc2In1 | Self::Universal)
50    }
51
52    /// Returns the default HarmonyOS ABI list when none is explicitly configured.
53    ///
54    /// # Returns
55    ///
56    /// - `Vec<HarmonyAbi>` - Default ABI selection for this form factor.
57    #[must_use]
58    pub fn default_abis(&self) -> Vec<HarmonyAbi> {
59        if self.is_pc_target() {
60            vec![HarmonyAbi::Arm64V8a, HarmonyAbi::X86_64]
61        } else {
62            vec![HarmonyAbi::Arm64V8a]
63        }
64    }
65
66    /// Returns the JSON array interior for `module.json5` `"deviceTypes"`.
67    ///
68    /// # Returns
69    ///
70    /// - `&'static str` - Quoted JSON device type elements.
71    #[must_use]
72    pub fn module_device_types_json(&self) -> &'static str {
73        match self {
74            Self::Phone => HARMONY_MOD_DEV_PHONE,
75            Self::Tablet => HARMONY_MOD_DEV_TABLET,
76            Self::Pc2In1 => HARMONY_MOD_DEV_2IN1,
77            Self::Universal => HARMONY_MOD_DEV_UNIVERSAL,
78            Self::Foldable => HARMONY_MOD_DEV_FOLDABLE,
79            Self::Wearable => HARMONY_MOD_DEV_WEARABLE,
80            Self::Tv => HARMONY_MOD_DEV_TV,
81            Self::Car => HARMONY_MOD_DEV_CAR,
82        }
83    }
84
85    /// Returns the JSON array string for `module.json5` `"supportWindowMode"`.
86    ///
87    /// # Returns
88    ///
89    /// - `&'static str` - JSON array literal of supported window modes.
90    #[must_use]
91    pub fn support_window_modes_json(&self) -> &'static str {
92        match self {
93            Self::Wearable | Self::Tv => HARMONY_WIN_MODE_FULLSCREEN,
94            Self::Car => HARMONY_WIN_MODE_SPLIT,
95            Self::Phone | Self::Tablet | Self::Pc2In1 | Self::Universal | Self::Foldable => {
96                HARMONY_WIN_MODE_ALL
97            }
98        }
99    }
100
101    /// Returns optional `minWindowWidth` / `maxWindowHeight` properties for `module.json5`.
102    ///
103    /// # Returns
104    ///
105    /// - `&'static str` - Trailing JSON property snippet or empty string.
106    #[must_use]
107    pub fn window_limits_json(&self) -> &'static str {
108        match self {
109            Self::Tablet => HARMONY_WIN_LIMIT_TABLET,
110            Self::Pc2In1 => HARMONY_WIN_LIMIT_2IN1,
111            Self::Universal => HARMONY_WIN_LIMIT_UNIVERSAL,
112            Self::Phone | Self::Foldable | Self::Wearable | Self::Tv | Self::Car => "",
113        }
114    }
115}
116
117/// Toolchain mapping helpers for `HarmonyAbi`.
118impl HarmonyAbi {
119    /// Returns the OpenHarmony `entry/libs/<abi>` directory name.
120    ///
121    /// # Returns
122    ///
123    /// - `&'static str` - `"arm64-v8a"` or `"x86_64"`.
124    #[must_use]
125    pub fn as_abi_dir(&self) -> &'static str {
126        match self {
127            Self::Arm64V8a => HARMONY_ABI_ARM64,
128            Self::X86_64 => HARMONY_ABI_X86_64,
129        }
130    }
131
132    /// Returns the Rust compilation target triple for OpenHarmony.
133    ///
134    /// # Returns
135    ///
136    /// - `&'static str` - OpenHarmony Rust target triple.
137    #[must_use]
138    pub fn rust_triple(&self) -> &'static str {
139        match self {
140            Self::Arm64V8a => HARMONY_TRIPLE_ARM64,
141            Self::X86_64 => HARMONY_TRIPLE_X86_64,
142        }
143    }
144
145    /// Returns the OHOS clang `--target` triple string.
146    ///
147    /// # Returns
148    ///
149    /// - `&'static str` - OHOS LLVM target triple.
150    #[must_use]
151    pub fn clang_triple(&self) -> &'static str {
152        match self {
153            Self::Arm64V8a => HARMONY_CLANG_ARM64,
154            Self::X86_64 => HARMONY_CLANG_X86_64,
155        }
156    }
157
158    /// Returns the lowercase underscore suffix for `CC_<triple>`.
159    ///
160    /// # Returns
161    ///
162    /// - `&'static str` - Lowercase Cargo env triple key.
163    #[must_use]
164    pub fn env_triple(&self) -> &'static str {
165        match self {
166            Self::Arm64V8a => HARMONY_ENV_ARM64,
167            Self::X86_64 => HARMONY_ENV_X86_64,
168        }
169    }
170
171    /// Returns the Cargo target linker environment variable name for this OHOS ABI.
172    ///
173    /// # Returns
174    ///
175    /// - `&'static str` - `CARGO_TARGET_<TRIPLE>_LINKER` variable name.
176    #[must_use]
177    pub fn cargo_linker_env(&self) -> &'static str {
178        match self {
179            Self::Arm64V8a => HARMONY_LINKER_ENV_ARM64,
180            Self::X86_64 => HARMONY_LINKER_ENV_X86_64,
181        }
182    }
183}
184
185/// Vendor specification helpers for `MiniAppVendor`.
186impl MiniAppVendor {
187    /// Returns the canonical lowercase vendor directory and CLI label.
188    ///
189    /// # Returns
190    ///
191    /// - `&'static str` - Canonical MiniApp vendor name.
192    #[must_use]
193    pub fn as_label(&self) -> &'static str {
194        match self {
195            Self::Wechat => VENDOR_WECHAT,
196            Self::Alipay => VENDOR_ALIPAY,
197            Self::Douyin => VENDOR_DOUYIN,
198            Self::Baidu => VENDOR_BAIDU,
199            Self::Qq => VENDOR_QQ,
200            Self::Kuaishou => VENDOR_KUAISHOU,
201            Self::Jd => VENDOR_JD,
202            Self::Xhs => VENDOR_XHS,
203            Self::Dingtalk => VENDOR_DINGTALK,
204            Self::Feishu => VENDOR_FEISHU,
205            Self::Taobao => VENDOR_TAOBAO,
206            Self::Meituan => VENDOR_MEITUAN,
207            Self::HarmonyAtomic => VENDOR_HARMONY_ATOMIC,
208        }
209    }
210
211    /// Returns the JavaScript host API namespace (`wx`, `my`, `tt`, `swan`, etc.).
212    ///
213    /// # Returns
214    ///
215    /// - `&'static str` - Host global API object name.
216    #[must_use]
217    pub fn api_namespace(&self) -> &'static str {
218        match self {
219            Self::Wechat => "wx",
220            Self::Alipay | Self::Taobao => "my",
221            Self::Douyin | Self::Feishu => "tt",
222            Self::Baidu => NS_SWAN,
223            Self::Qq => "qq",
224            Self::Kuaishou => "ks",
225            Self::Jd => "jd",
226            Self::Xhs => NS_XHS,
227            Self::Dingtalk => "dd",
228            Self::Meituan => "mt",
229            Self::HarmonyAtomic => "",
230        }
231    }
232
233    /// Returns the vendor page markup file extension (`wxml`, `axml`, `ttml`, etc.).
234    ///
235    /// # Returns
236    ///
237    /// - `&'static str` - Markup extension without leading dot.
238    #[must_use]
239    pub fn markup_ext(&self) -> &'static str {
240        match self {
241            Self::Wechat => EXT_WXML,
242            Self::Alipay | Self::Dingtalk | Self::Taobao => EXT_AXML,
243            Self::Douyin | Self::Feishu => EXT_TTML,
244            Self::Baidu => EXT_SWAN,
245            Self::Qq => EXT_QML,
246            Self::Kuaishou => EXT_KSML,
247            Self::Jd => EXT_JXML,
248            Self::Xhs => EXT_XHSML,
249            Self::Meituan => EXT_MXML,
250            Self::HarmonyAtomic => "",
251        }
252    }
253
254    /// Returns the vendor stylesheet file extension (`wxss`, `acss`, `ttss`, `css`, etc.).
255    ///
256    /// # Returns
257    ///
258    /// - `&'static str` - Stylesheet extension without leading dot.
259    #[must_use]
260    pub fn style_ext(&self) -> &'static str {
261        match self {
262            Self::Wechat => EXT_WXSS,
263            Self::Alipay | Self::Dingtalk | Self::Taobao => EXT_ACSS,
264            Self::Douyin | Self::Feishu => EXT_TTSS,
265            Self::Baidu | Self::Kuaishou | Self::Xhs => ECO_EXT_CSS,
266            Self::Qq => EXT_QSS,
267            Self::Jd => EXT_JXSS,
268            Self::Meituan => EXT_MXSS,
269            Self::HarmonyAtomic => "",
270        }
271    }
272
273    /// Returns the vendor IDE project configuration filename.
274    ///
275    /// # Returns
276    ///
277    /// - `&'static str` - Config filename at project root.
278    #[must_use]
279    pub fn config_file(&self) -> &'static str {
280        match self {
281            Self::Alipay | Self::Dingtalk | Self::Taobao => MINIAPP_CFG_MINI_PROJECT,
282            Self::Baidu => MINIAPP_CFG_SWAN,
283            Self::HarmonyAtomic => "",
284            Self::Wechat
285            | Self::Douyin
286            | Self::Qq
287            | Self::Kuaishou
288            | Self::Jd
289            | Self::Xhs
290            | Self::Feishu
291            | Self::Meituan => MINIAPP_CFG_PROJECT_CONFIG,
292        }
293    }
294
295    /// Returns whether this vendor uses Alipay-style markup events (`onTouchStart` vs `bindtouchstart`).
296    ///
297    /// # Returns
298    ///
299    /// - `bool` - `true` for Alipay, DingTalk, and Taobao.
300    #[must_use]
301    pub fn uses_alipay_syntax(&self) -> bool {
302        matches!(self, Self::Alipay | Self::Dingtalk | Self::Taobao)
303    }
304
305    /// Returns the vendor WebAssembly global identifier (`WXWebAssembly`, `MYWebAssembly`, etc.).
306    ///
307    /// # Returns
308    ///
309    /// - `&'static str` - Vendor WebAssembly global symbol name.
310    #[must_use]
311    pub fn wasm_global(&self) -> &'static str {
312        match self {
313            Self::Wechat => WASM_GLOBAL_WX,
314            Self::Alipay | Self::Dingtalk | Self::Taobao => WASM_GLOBAL_MY,
315            Self::Douyin | Self::Feishu => WASM_GLOBAL_TT,
316            Self::Qq => WASM_GLOBAL_QQ,
317            Self::Baidu
318            | Self::Kuaishou
319            | Self::Jd
320            | Self::Xhs
321            | Self::Meituan
322            | Self::HarmonyAtomic => WASM_GLOBAL_STD,
323        }
324    }
325}
326
327/// Vendor specification helpers for `QuickAppVendor`.
328impl QuickAppVendor {
329    /// Returns the canonical lowercase QuickApp vendor label (`alliance` or `huawei`).
330    ///
331    /// # Returns
332    ///
333    /// - `&'static str` - QuickApp vendor directory name.
334    #[must_use]
335    pub fn as_label(&self) -> &'static str {
336        match self {
337            Self::Alliance => VENDOR_ALLIANCE,
338            Self::Huawei => VENDOR_HUAWEI,
339        }
340    }
341
342    /// Returns the QuickApp application package identifier for `src/manifest.json`.
343    ///
344    /// # Returns
345    ///
346    /// - `&'static str` - QuickApp package ID.
347    #[must_use]
348    pub fn package_id(&self) -> &'static str {
349        match self {
350            Self::Alliance => QUICKAPP_ALLIANCE_PKG_ID,
351            Self::Huawei => QUICKAPP_HUAWEI_PKG_ID,
352        }
353    }
354
355    /// Returns the minimum QuickApp platform version integer (`1100`).
356    ///
357    /// # Returns
358    ///
359    /// - `u32` - Minimum platform version.
360    #[must_use]
361    pub fn min_platform_version(&self) -> u32 {
362        QUICKAPP_MIN_PLATFORM_VERSION
363    }
364}
365
366/// Vendor specification helpers for `WearableVendor`.
367impl WearableVendor {
368    /// Returns the canonical lowercase wearable vendor directory label.
369    ///
370    /// # Returns
371    ///
372    /// - `&'static str` - Wearable vendor label.
373    #[must_use]
374    pub fn as_label(&self) -> &'static str {
375        match self {
376            Self::WearOs => VENDOR_WEAROS,
377            Self::WatchOs => VENDOR_WATCHOS,
378            Self::HarmonyWatch => VENDOR_HARMONY_WATCH,
379            Self::Vela => VENDOR_VELA,
380            Self::VivoWatch => VENDOR_VIVO_WATCH,
381            Self::OppoWatch => VENDOR_OPPO_WATCH,
382            Self::Garmin => VENDOR_GARMIN,
383            Self::ZeppOs => VENDOR_ZEPPOS,
384        }
385    }
386
387    /// Returns whether this wearable target consumes the shared zero-DOM WASM core.
388    ///
389    /// # Returns
390    ///
391    /// - `bool` - `true` for `Vela`, `VivoWatch`, and `ZeppOs`.
392    #[must_use]
393    pub fn uses_shared_wasm_core(&self) -> bool {
394        matches!(self, Self::Vela | Self::VivoWatch | Self::ZeppOs)
395    }
396}
397
398/// Default configuration builder for `SharedWasmHostConfig`.
399impl Default for SharedWasmHostConfig {
400    /// Creates a release zero-DOM WASM host config rooted at `.`.
401    ///
402    /// # Returns
403    ///
404    /// - `Self` - Default `SharedWasmHostConfig`.
405    fn default() -> Self {
406        Self {
407            workspace_root: PathBuf::from("."),
408            stage_dir: None,
409            release: true,
410            skip_wasm_opt: false,
411            reuse_existing: false,
412        }
413    }
414}
415
416/// Default configuration builder for `HarmonyBuildConfig`.
417impl Default for HarmonyBuildConfig {
418    /// Creates a HarmonyOS phone build configuration rooted at `.`.
419    ///
420    /// # Returns
421    ///
422    /// - `Self` - Default `HarmonyBuildConfig`.
423    fn default() -> Self {
424        Self {
425            workspace_root: PathBuf::from("."),
426            device_kind: HarmonyDeviceKind::Phone,
427            abis: Vec::new(),
428            app_version: None,
429            out_dir: None,
430            build_dir: None,
431            ohos_sdk_root: None,
432            shell_only: false,
433            install_hap: false,
434        }
435    }
436}
437
438/// Default configuration builder for `MiniAppBuildConfig`.
439impl Default for MiniAppBuildConfig {
440    /// Creates a release MiniApp build configuration targeting all 13 vendors.
441    ///
442    /// # Returns
443    ///
444    /// - `Self` - Default `MiniAppBuildConfig`.
445    fn default() -> Self {
446        Self {
447            workspace_root: PathBuf::from("."),
448            vendors: Vec::new(),
449            app_version: None,
450            out_base: None,
451            release: true,
452            shell_only: false,
453            skip_wasm_opt: false,
454        }
455    }
456}
457
458/// Default configuration builder for `QuickAppBuildConfig`.
459impl Default for QuickAppBuildConfig {
460    /// Creates a release QuickApp build configuration targeting both Alliance and Huawei.
461    ///
462    /// # Returns
463    ///
464    /// - `Self` - Default `QuickAppBuildConfig`.
465    fn default() -> Self {
466        Self {
467            workspace_root: PathBuf::from("."),
468            vendors: Vec::new(),
469            app_version: None,
470            out_base: None,
471            release: true,
472            shell_only: false,
473            skip_wasm_opt: false,
474        }
475    }
476}
477
478/// Default configuration builder for `WearableBuildConfig`.
479impl Default for WearableBuildConfig {
480    /// Creates a release Wearable build configuration targeting all 8 smartwatch ecosystems.
481    ///
482    /// # Returns
483    ///
484    /// - `Self` - Default `WearableBuildConfig`.
485    fn default() -> Self {
486        Self {
487            workspace_root: PathBuf::from("."),
488            vendors: Vec::new(),
489            app_version: None,
490            out_base: None,
491            release: true,
492            shell_only: false,
493            install: false,
494            skip_wasm_opt: false,
495        }
496    }
497}