Skip to main content

euv_cli/builder/desktop/
impl.rs

1use super::*;
2
3/// Target metadata and CI release naming helpers for `DesktopTargetKind`.
4impl DesktopTargetKind {
5    /// Returns the desktop target matching the current host operating system.
6    ///
7    /// # Returns
8    ///
9    /// - `Self` - `Macos`, `Windows`, or `Linux` based on `cfg!(target_os)`.
10    #[must_use]
11    pub fn current_host() -> Self {
12        if cfg!(target_os = "macos") {
13            Self::Macos
14        } else if cfg!(target_os = "windows") {
15            Self::Windows
16        } else {
17            Self::Linux
18        }
19    }
20
21    /// Maps a CLI `TargetArg` into a `DesktopTargetKind` when supported.
22    ///
23    /// # Arguments
24    ///
25    /// - `TargetArg` - Parsed CLI target selector.
26    ///
27    /// # Returns
28    ///
29    /// - `Option<Self>` - Matching desktop/terminal target kind or `None` for non-desktop targets.
30    #[must_use]
31    pub fn from_target_arg(target: TargetArg) -> Option<Self> {
32        match target {
33            TargetArg::Macos => Some(Self::Macos),
34            TargetArg::Windows => Some(Self::Windows),
35            TargetArg::Linux => Some(Self::Linux),
36            TargetArg::Tui => Some(Self::Tui),
37            TargetArg::Cli => Some(Self::Cli),
38            TargetArg::Native => Some(Self::current_host()),
39            _ => None,
40        }
41    }
42
43    /// Returns the canonical lowercase platform label (`macos`, `windows`, `linux`, `tui`, `cli`).
44    ///
45    /// # Arguments
46    ///
47    /// - `&Self` - Desktop target kind.
48    ///
49    /// # Returns
50    ///
51    /// - `&'static str` - Canonical lowercase platform label.
52    #[must_use]
53    pub fn platform_label(&self) -> &'static str {
54        match self {
55            Self::Macos => DESKTOP_LABEL_MACOS,
56            Self::Windows => DESKTOP_LABEL_WINDOWS,
57            Self::Linux => DESKTOP_LABEL_LINUX,
58            Self::Tui => DESKTOP_LABEL_TUI,
59            Self::Cli => DESKTOP_LABEL_CLI,
60        }
61    }
62
63    /// Returns the default architecture label matching CI release naming (`arm64` or `x86_64`).
64    ///
65    /// # Arguments
66    ///
67    /// - `&Self` - Desktop target kind.
68    ///
69    /// # Returns
70    ///
71    /// - `&'static str` - Architecture label string.
72    #[must_use]
73    pub fn default_arch(&self) -> &'static str {
74        match self {
75            Self::Macos => DESKTOP_ARCH_ARM64,
76            Self::Windows | Self::Linux => DESKTOP_ARCH_X86_64,
77            Self::Tui | Self::Cli => {
78                if cfg!(target_arch = "aarch64") {
79                    DESKTOP_ARCH_ARM64
80                } else {
81                    DESKTOP_ARCH_X86_64
82                }
83            }
84        }
85    }
86
87    /// Returns the platform executable suffix (`".exe"` on Windows, `""` otherwise).
88    ///
89    /// # Arguments
90    ///
91    /// - `&Self` - Desktop target kind.
92    ///
93    /// # Returns
94    ///
95    /// - `&'static str` - Executable filename suffix.
96    #[must_use]
97    pub fn exe_suffix(&self) -> &'static str {
98        match self {
99            Self::Windows => DESKTOP_EXE_SUFFIX_WINDOWS,
100            Self::Tui | Self::Cli if cfg!(target_os = "windows") => DESKTOP_EXE_SUFFIX_WINDOWS,
101            _ => "",
102        }
103    }
104
105    /// Returns the default CI archive extension (`"zip"` on Windows, `"tar.gz"` on Unix).
106    ///
107    /// # Arguments
108    ///
109    /// - `&Self` - Desktop target kind.
110    ///
111    /// # Returns
112    ///
113    /// - `&'static str` - Archive extension without leading dot.
114    #[must_use]
115    pub fn default_archive_ext(&self) -> &'static str {
116        match self {
117            Self::Windows => DESKTOP_ARCHIVE_EXT_ZIP,
118            Self::Tui | Self::Cli if cfg!(target_os = "windows") => DESKTOP_ARCHIVE_EXT_ZIP,
119            _ => DESKTOP_ARCHIVE_EXT_TAR_GZ,
120        }
121    }
122
123    /// Returns the default staging directory path (`dist/client-<platform>`).
124    ///
125    /// # Arguments
126    ///
127    /// - `&Self` - Desktop target kind.
128    ///
129    /// # Returns
130    ///
131    /// - `PathBuf` - Default output directory path.
132    #[must_use]
133    pub fn default_out_dir(&self) -> PathBuf {
134        PathBuf::from(format!("{DESKTOP_OUT_DIR_PREFIX}{}", self.platform_label()))
135    }
136
137    /// Returns the canonical GitHub Release asset filename (`euv-<version>-<platform>-<arch>.<ext>`).
138    ///
139    /// # Arguments
140    ///
141    /// - `&Self` - Desktop target kind.
142    /// - `&str` - Semantic version string.
143    ///
144    /// # Returns
145    ///
146    /// - `String` - Exact CI release asset filename.
147    #[must_use]
148    pub fn default_release_asset_name(&self, version: &str) -> String {
149        format!(
150            "{DESKTOP_CLI_BIN_NAME}-{version}-{}-{}.{}",
151            self.platform_label(),
152            self.default_arch(),
153            self.default_archive_ext()
154        )
155    }
156
157    /// Returns the native platform icon filename when this target expects a staged icon.
158    ///
159    /// # Arguments
160    ///
161    /// - `&Self` - Desktop target kind.
162    ///
163    /// # Returns
164    ///
165    /// - `Option<&'static str>` - Icon filename (`euv.icns`, `euv.ico`, `euv.png`) or `None` for terminal targets.
166    #[must_use]
167    pub fn icon_filename(&self) -> Option<&'static str> {
168        match self {
169            Self::Macos => Some(DESKTOP_ICON_MACOS),
170            Self::Windows => Some(DESKTOP_ICON_WINDOWS),
171            Self::Linux => Some(DESKTOP_ICON_LINUX),
172            Self::Tui | Self::Cli => None,
173        }
174    }
175}
176
177/// Default configuration targeting the current host desktop platform in release mode.
178impl Default for DesktopBuildConfig {
179    /// Constructs a release `DesktopBuildConfig` for the current host platform.
180    ///
181    /// # Returns
182    ///
183    /// - `Self` - Default desktop build configuration.
184    fn default() -> Self {
185        let host_target: DesktopTargetKind = DesktopTargetKind::current_host();
186        Self {
187            repo_root: PathBuf::from("."),
188            target: host_target,
189            package: None,
190            target_triple: None,
191            out_dir: host_target.default_out_dir(),
192            archive_path: None,
193            icon_path: None,
194            version: None,
195            features: Vec::new(),
196            release: true,
197            include_cli: false,
198            smoke: false,
199            verify_ai_schema: true,
200        }
201    }
202}