wick_component_codegen/generate/
config.rs

1use std::collections::HashSet;
2use std::path::{Path, PathBuf};
3
4use derive_builder::Builder;
5
6use super::dependency::Dependency;
7
8#[derive(Debug, Default, Builder, Clone)]
9#[must_use]
10pub struct Config {
11  #[builder(setter(into))]
12  #[builder(default = "std::env::var(\"OUT_DIR\").map(Into::into).unwrap_or_default()")]
13  pub(crate) out_dir: PathBuf,
14  #[builder(default)]
15  pub(crate) raw: bool,
16  #[builder(setter(into))]
17  pub(crate) spec: PathBuf,
18  #[builder(default = "true")]
19  pub(crate) op_traits: bool,
20  #[builder(default = "true")]
21  pub(crate) components: bool,
22  #[builder(default = "true")]
23  pub(crate) output_structs: bool,
24  #[builder(setter(skip))]
25  pub(crate) deps: HashSet<Dependency>,
26}
27
28impl Config {
29  pub fn new() -> Self {
30    Self::default()
31  }
32
33  pub(crate) fn add_dep(&mut self, dep: Dependency) {
34    self.deps.insert(dep);
35  }
36
37  pub fn exec(self) -> anyhow::Result<()> {
38    super::build(self)?;
39    Ok(())
40  }
41}
42
43impl ConfigBuilder {
44  pub fn new() -> Self {
45    Self::default()
46  }
47  pub fn generate(&mut self, spec: impl AsRef<Path>) -> anyhow::Result<()> {
48    let config = self.spec(spec.as_ref().to_path_buf()).build()?;
49    super::build(config)?;
50
51    Ok(())
52  }
53}
54
55#[must_use]
56pub fn configure() -> ConfigBuilder {
57  ConfigBuilder::default()
58}