use std::str::FromStr;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CanisterBuildProfile {
Debug,
Fast,
Release,
}
impl CanisterBuildProfile {
#[must_use]
pub fn current() -> Self {
match std::env::var("CANIC_WASM_PROFILE").ok().as_deref() {
Some("debug") => Self::Debug,
Some("fast") => Self::Fast,
_ => Self::Release,
}
}
#[must_use]
pub const fn cargo_args(self) -> &'static [&'static str] {
match self {
Self::Debug => &[],
Self::Fast => &["--profile", "fast"],
Self::Release => &["--release"],
}
}
#[must_use]
pub const fn target_dir_name(self) -> &'static str {
match self {
Self::Debug => "debug",
Self::Fast => "fast",
Self::Release => "release",
}
}
}
impl FromStr for CanisterBuildProfile {
type Err = String;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"debug" => Ok(Self::Debug),
"fast" => Ok(Self::Fast),
"release" => Ok(Self::Release),
_ => Err(format!(
"invalid build profile {value}; use debug, fast, or release"
)),
}
}
}