use std::{env, path::PathBuf};
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum Language {
Rust,
C,
Lua,
#[default]
All,
}
#[derive(Default, Debug)]
pub struct TrixyConfig {
pub trixy_path: PathBuf,
pub host_code_name: String,
pub c_header_name: String,
pub add_c_headers: bool,
pub dist_dir_path: Option<PathBuf>,
pub callback_function: String,
pub out_dir_path: PathBuf,
pub generate_auxiliary: bool,
pub generate_host: bool,
}
impl TrixyConfig {
pub fn new<T: Into<String>>(callback_function: T) -> Self {
let out_dir;
if let Ok(out_dir_new) = env::var("OUT_DIR") {
let out_path = PathBuf::from(out_dir_new);
out_dir = out_path;
} else {
out_dir = PathBuf::default();
};
Self {
callback_function: callback_function.into(),
host_code_name: "api.rs".into(),
c_header_name: "interface.h".into(),
out_dir_path: out_dir,
add_c_headers: true,
generate_auxiliary: true,
generate_host: true,
..Default::default()
}
}
pub fn trixy_path<T: Into<PathBuf>>(self, input_path: T) -> Self {
Self {
trixy_path: input_path.into(),
..self
}
}
pub fn add_c_headers<T: Into<bool>>(self, add_c_headers: T) -> Self {
Self {
add_c_headers: add_c_headers.into(),
..self
}
}
pub fn generate_host<T: Into<bool>>(self, host: T) -> Self {
Self {
generate_host: host.into(),
..self
}
}
pub fn generate_auxiliary<T: Into<bool>>(self, auxiliary: T) -> Self {
Self {
generate_auxiliary: auxiliary.into(),
..self
}
}
pub fn dist_dir_path<T: Into<PathBuf>>(self, dist_dir_path: T) -> Self {
Self {
dist_dir_path: Some(dist_dir_path.into()),
..self
}
}
pub fn host_code_name<T: Into<String>>(self, output_path: T) -> Self {
Self {
host_code_name: output_path.into(),
..self
}
}
pub fn out_dir_path<T: Into<PathBuf>>(self, out_dir: T) -> Self {
Self {
out_dir_path: out_dir.into(),
..self
}
}
pub fn c_header_name<T: Into<String>>(self, output_path: T) -> Self {
Self {
c_header_name: output_path.into(),
..self
}
}
pub fn callback_function<T: Into<String>>(self, callback_function: T) -> Self {
Self {
callback_function: callback_function.into(),
..self
}
}
}