Skip to content

Commit ac5c649

Browse files
authored
[4/n] add configuration for target presets (#72)
Add a `target.preset` table which can be used to define presets for target configuration. This will be used within omicron-package. For how this will eventually be used, see oxidecomputer/omicron#7288.
1 parent cf283ea commit ac5c649

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/config/identifier.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ impl FromStr for ConfigIdent {
174174
}
175175
}
176176

177+
// The `Deserialize` implementation for `ConfigIdent` must be manually
178+
// implemented, because it must go through validation. The `Serialize`
179+
// implementation can be derived because `ConfigIdent` serializes as a regular
180+
// string.
177181
impl<'de> Deserialize<'de> for ConfigIdent {
178182
fn deserialize<D>(deserializer: D) -> Result<ConfigIdent, D::Error>
179183
where

src/config/imp.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::path::Path;
1212
use thiserror::Error;
1313
use topological_sort::TopologicalSort;
1414

15-
use super::PackageName;
15+
use super::{PackageName, PresetName};
1616

1717
/// Describes a set of packages to act upon.
1818
///
@@ -106,6 +106,10 @@ pub struct Config {
106106
/// Packages to be built and installed.
107107
#[serde(default, rename = "package")]
108108
pub packages: BTreeMap<PackageName, Package>,
109+
110+
/// Target configuration.
111+
#[serde(default)]
112+
pub target: TargetConfig,
109113
}
110114

111115
impl Config {
@@ -134,6 +138,14 @@ impl Config {
134138
}
135139
}
136140

141+
/// Configuration for targets, including preset configuration.
142+
#[derive(Clone, Deserialize, Debug, Default)]
143+
pub struct TargetConfig {
144+
/// Preset configuration for targets.
145+
#[serde(default, rename = "preset")]
146+
pub presets: BTreeMap<PresetName, TargetMap>,
147+
}
148+
137149
/// Errors which may be returned when parsing the server configuration.
138150
#[derive(Error, Debug)]
139151
pub enum ParseError {
@@ -187,6 +199,7 @@ mod test {
187199
(pkg_a_name.clone(), pkg_a.clone()),
188200
(pkg_b_name.clone(), pkg_b.clone()),
189201
]),
202+
target: TargetConfig::default(),
190203
};
191204

192205
let mut order = cfg.packages_to_build(&TargetMap::default()).build_order();
@@ -228,6 +241,7 @@ mod test {
228241
(pkg_a_name.clone(), pkg_a.clone()),
229242
(pkg_b_name.clone(), pkg_b.clone()),
230243
]),
244+
target: TargetConfig::default(),
231245
};
232246

233247
let mut order = cfg.packages_to_build(&TargetMap::default()).build_order();
@@ -253,6 +267,7 @@ mod test {
253267

254268
let cfg = Config {
255269
packages: BTreeMap::from([(pkg_a_name.clone(), pkg_a.clone())]),
270+
target: TargetConfig::default(),
256271
};
257272

258273
let mut order = cfg.packages_to_build(&TargetMap::default()).build_order();

0 commit comments

Comments
 (0)