Files
pallet/src/config.rs

57 lines
1.4 KiB
Rust
Raw Normal View History

#[derive(serde::Deserialize, serde::Serialize, Default)]
2026-03-22 11:16:14 -05:00
pub struct Config {
/// 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>>,
2026-03-22 11:16:14 -05:00
/// 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()],
..Default::default()
2026-03-22 11:16:14 -05:00
}
}
2026-03-22 18:04:40 -05:00
pub fn get_or_default(&self, mode: &Option<String>) -> Option<&BuildConf> {
2026-03-22 11:16:14 -05:00
if let Some(mode) = mode {
2026-03-22 18:04:40 -05:00
self.build.iter().find(|bc| bc.name == *mode)
2026-03-22 11:16:14 -05:00
} 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()],
}
}
}