euv-cli 0.50.0

Cross-platform CLI tool for the euv native UI framework supporting run, build, check, fmt, doctor, new, and Hyperlane SSE dynamic updates across all supported platforms.
Documentation
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,
        }
    }
}