initial commit
This commit is contained in:
49
src/config.rs
Normal file
49
src/config.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
pub struct Config {
|
||||
/// The name of the output binary
|
||||
pub name: String,
|
||||
/// The default build to use
|
||||
pub default_build: String,
|
||||
/// Build configs
|
||||
pub build: Vec<BuildConf>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(name: &str) -> Self {
|
||||
Self {
|
||||
name: name.to_owned(),
|
||||
default_build: "debug".to_owned(),
|
||||
build: vec![BuildConf::debug(), BuildConf::release()],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_or_default(&self, mode: Option<String>) -> 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<String>,
|
||||
}
|
||||
|
||||
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()],
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user