Skip to main content

harmos_packaging/
config.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10// Build And Development Process Settings.
11
12/* === Modules === */
13
14/* === Re-Exports === */
15
16/* === Imports === */
17
18// Standard Library Imports
19use std::time::Duration;
20
21// Third Party Imports
22
23// Local Imports
24
25/* === Constants === */
26
27/* === Macros === */
28
29/* === Type Aliases === */
30
31/* === Structs === */
32
33#[derive(Clone, Debug)]
34pub struct BuildSettings {
35    pub backend: BuildBackend,
36    pub manifest: std::path::PathBuf,
37    pub packages: Vec<String>,
38    pub target: Option<String>,
39    pub target_directory: Option<std::path::PathBuf>,
40    pub profile: BuildProfile,
41    pub timings: bool,
42    pub features: Vec<String>,
43    pub default_features: bool,
44}
45
46#[derive(Clone, Copy, Debug)]
47pub struct DevSettings {
48    pub debounce: Duration,
49}
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
52#[serde(rename_all = "snake_case")]
53pub enum BuildBackend {
54    Sidecar,
55    Guest,
56}
57
58/* === Enums === */
59
60#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
61#[serde(rename_all = "snake_case")]
62pub enum BuildProfile {
63    Dev,
64    Release,
65    Bench,
66}
67
68/* === Traits === */
69
70/* === Implementations === */
71
72impl BuildProfile {
73    pub const fn name(self) -> &'static str {
74        match self {
75            Self::Dev => "dev",
76            Self::Release => "release",
77            Self::Bench => "bench",
78        }
79    }
80}
81
82impl std::str::FromStr for BuildProfile {
83    type Err = &'static str;
84    fn from_str(value: &str) -> Result<Self, Self::Err> {
85        match value {
86            "dev" => Ok(Self::Dev),
87            "release" => Ok(Self::Release),
88            "bench" => Ok(Self::Bench),
89            _ => Err("profile must be dev, release or bench"),
90        }
91    }
92}
93
94impl Default for BuildSettings {
95    fn default() -> Self {
96        Self {
97            backend: BuildBackend::Sidecar,
98            manifest: "Cargo.toml".into(),
99            packages: Vec::new(),
100            target: None,
101            target_directory: None,
102            profile: BuildProfile::Dev,
103            timings: false,
104            features: Vec::new(),
105            default_features: true,
106        }
107    }
108}
109
110impl Default for DevSettings {
111    fn default() -> Self {
112        Self { debounce: Duration::from_millis(100) }
113    }
114}
115
116/* === Public Functions === */
117
118/* === Private Functions === */
119
120/* === Tests === */