#[derive(serde::Deserialize, serde::Serialize, Default)] pub struct Config { /// The C compiler to use (defaults to "gcc") pub compiler: Option, /// The name of the output binary pub name: String, /// The default build to use pub default_build: String, /// A brief description pub description: Option, /// The version of the project pub version: Option, /// The authors of the project pub authors: Option>, /// Build configs pub build: Vec, /// Build dependnecies verified by pkg-config pub dependencies: Option>, } impl Config { pub fn new(name: &str) -> Self { Self { name: name.to_owned(), default_build: "debug".to_owned(), build: vec![BuildConf::debug(), BuildConf::release()], ..Default::default() } } pub fn get_or_default(&self, mode: &Option) -> Option<&BuildConf> { if let Some(mode) = mode { self.build.iter().find(|bc| bc.name == *mode) } else { self.build.iter().find(|bc| bc.name == self.default_build) } } } #[derive(serde::Deserialize, serde::Serialize)] pub struct BuildConf { pub name: String, pub args: Vec, } impl BuildConf { fn debug() -> Self { Self { name: "debug".to_owned(), args: vec!["-g".to_owned(), "-O0".to_owned()], } } fn release() -> Self { Self { name: "release".to_owned(), args: vec!["-DNDEBUG".to_owned(), "-O3".to_owned()], } } }