Reviewed-on: http://192.168.1.227:3000/sfrembling/pallet/pulls/14 Co-authored-by: godsfryingpan <sfrembling@gmail.com> Co-committed-by: godsfryingpan <sfrembling@gmail.com>
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
#[derive(serde::Deserialize, serde::Serialize, Default)]
|
|
pub struct Config {
|
|
/// The C compiler to use (defaults to "gcc")
|
|
pub compiler: Option<String>,
|
|
/// The name of the output binary
|
|
pub name: String,
|
|
/// The default build to use
|
|
pub default_build: String,
|
|
/// A brief description
|
|
pub description: Option<String>,
|
|
/// The version of the project
|
|
pub version: Option<String>,
|
|
/// The authors of the project
|
|
pub authors: Option<Vec<String>>,
|
|
/// Build configs
|
|
pub build: Vec<BuildConf>,
|
|
/// Build dependnecies verified by pkg-config
|
|
pub dependencies: Option<Vec<String>>,
|
|
}
|
|
|
|
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<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()],
|
|
}
|
|
}
|
|
}
|