use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
#[serde(deny_unknown_fields)]
pub struct SymlinkInstallConfig {
#[serde(default)]
pub sources: Vec<String>,
#[serde(default)]
pub targets: Vec<String>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct PagesConfig {
pub dir: String,
}
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
#[serde(deny_unknown_fields)]
pub struct CommandsConfig {
#[serde(default)]
pub symlink_install: SymlinkInstallConfig,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct BuildConfig {
#[serde(default = "default_parallel")]
pub parallel: usize,
#[serde(default)]
pub batch_size: usize,
#[serde(default = "default_output_dir")]
pub output_dir: String,
#[serde(default = "default_max_arg_len")]
pub max_arg_len: usize,
#[serde(default = "default_max_discovery_passes")]
pub max_discovery_passes: usize,
#[serde(default = "default_hash_tool_versions")]
pub hash_tool_versions: bool,
#[serde(default = "default_warn_symlinks")]
pub warn_symlinks: bool,
#[serde(default = "default_allow_missing_dep_auto")]
pub allow_missing_dep_auto: bool,
#[serde(default = "default_allow_missing_src_dirs")]
pub allow_missing_src_dirs: bool,
#[serde(default = "default_reject_dot_src_dirs")]
pub reject_dot_src_dirs: bool,
#[serde(default)]
pub command_timeout_secs: u64,
#[serde(default = "default_worker_stack_mib")]
pub worker_stack_mib: usize,
}
const fn default_parallel() -> usize {
0
}
fn default_output_dir() -> String {
"out".into()
}
const fn default_max_arg_len() -> usize {
1_000_000
}
const fn default_max_discovery_passes() -> usize {
10
}
const fn default_hash_tool_versions() -> bool {
true
}
const fn default_warn_symlinks() -> bool {
false
}
const fn default_allow_missing_dep_auto() -> bool {
false
}
const fn default_allow_missing_src_dirs() -> bool {
false
}
const fn default_reject_dot_src_dirs() -> bool {
false
}
const fn default_worker_stack_mib() -> usize {
256
}
impl Default for BuildConfig {
fn default() -> Self {
Self {
parallel: 0,
batch_size: 0, output_dir: "out".into(),
max_arg_len: default_max_arg_len(),
max_discovery_passes: default_max_discovery_passes(),
hash_tool_versions: default_hash_tool_versions(),
warn_symlinks: default_warn_symlinks(),
allow_missing_dep_auto: default_allow_missing_dep_auto(),
allow_missing_src_dirs: default_allow_missing_src_dirs(),
reject_dot_src_dirs: default_reject_dot_src_dirs(),
command_timeout_secs: 0,
worker_stack_mib: default_worker_stack_mib(),
}
}
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, Default, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum RestoreMethod {
#[default]
Auto,
Hardlink,
Copy,
}
impl RestoreMethod {
pub fn resolve(self) -> Self {
match self {
Self::Auto => {
if std::env::var("CI").is_ok_and(|v| v == "true") {
Self::Copy
} else {
Self::Hardlink
}
}
other => other,
}
}
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct CacheConfig {
#[serde(default)]
pub restore_method: RestoreMethod,
#[serde(default)]
pub compression: bool,
#[serde(default)]
pub remote: Option<String>,
#[serde(default = "default_true")]
pub remote_push: bool,
#[serde(default = "default_true")]
pub remote_pull: bool,
#[serde(default = "default_true")]
pub mtime_check: bool,
#[serde(default = "default_webcache_ttl_secs")]
pub webcache_ttl_secs: u64,
}
const fn default_webcache_ttl_secs() -> u64 {
7 * 24 * 60 * 60
}
impl Default for CacheConfig {
fn default() -> Self {
Self {
restore_method: RestoreMethod::default(),
compression: false,
remote: None,
remote_push: true,
remote_pull: true,
mtime_check: true,
webcache_ttl_secs: default_webcache_ttl_secs(),
}
}
}
pub const fn default_true() -> bool {
true
}