Make standard optional, allow empty src_disable, and add none/custom kinds

This commit is contained in:
peoplemiau1
2026-05-29 18:57:45 +03:00
parent 478d1ad0c5
commit 0587965283
2 changed files with 24 additions and 19 deletions

View File

@@ -37,9 +37,6 @@ pub fn collect_sources(
collect_sources_rec(root, extensions, &mut sources, exclude_dirs, include_paths)?; collect_sources_rec(root, extensions, &mut sources, exclude_dirs, include_paths)?;
} }
sources.sort(); sources.sort();
if sources.is_empty() {
return Err(format!("No source files found in {}", format_roots(roots)));
}
Ok(sources) Ok(sources)
} }
@@ -89,17 +86,6 @@ fn collect_sources_rec(
Ok(()) Ok(())
} }
fn format_roots(roots: &[PathBuf]) -> String {
if roots.is_empty() {
return "<none>".to_string();
}
let mut out = Vec::new();
for root in roots {
out.push(root.to_string_lossy().to_string());
}
out.join(", ")
}
pub fn is_excluded(path: &Path, exclude_dirs: &[PathBuf], include_paths: &[String]) -> bool { pub fn is_excluded(path: &Path, exclude_dirs: &[PathBuf], include_paths: &[String]) -> bool {
if matches_patterns(path, include_paths, true) { if matches_patterns(path, include_paths, true) {
return false; return false;
@@ -624,7 +610,8 @@ mod tests {
let result = collect_sources(&roots, &["c"], &[], &include); let result = collect_sources(&roots, &["c"], &[], &include);
std::env::set_current_dir(prev).unwrap(); std::env::set_current_dir(prev).unwrap();
assert!(result.is_err(), "empty src should return error"); let sources = result.expect("empty src should return Ok");
assert!(sources.is_empty(), "empty src should return empty vec");
} }
#[test] #[test]

View File

@@ -27,7 +27,15 @@ const DEFAULT_LANGUAGE: &str = "c";
const DEFAULT_STANDARD: &str = "c11"; const DEFAULT_STANDARD: &str = "c11";
const DEFAULT_COMPILER: &str = "clang"; const DEFAULT_COMPILER: &str = "clang";
const DEFAULT_KIND: &str = "bin"; const DEFAULT_KIND: &str = "bin";
const VALID_KINDS: &[&str] = &["bin", "staticlib", "sharedlib", "efi", "elf"]; const VALID_KINDS: &[&str] = &[
"bin",
"staticlib",
"sharedlib",
"efi",
"elf",
"none",
"custom",
];
#[derive(Debug)] #[derive(Debug)]
pub enum ConfigError { pub enum ConfigError {
@@ -101,7 +109,8 @@ pub struct PackageConfig {
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct BuildConfig { pub struct BuildConfig {
pub language: LanguageConfig, pub language: LanguageConfig,
pub standard: String, #[serde(default)]
pub standard: Option<String>,
#[serde(default)] #[serde(default)]
pub cxx_standard: Option<String>, pub cxx_standard: Option<String>,
pub compiler: String, pub compiler: String,
@@ -353,7 +362,14 @@ impl Config {
} }
validate_language_config(&build.language, "build.language")?; validate_language_config(&build.language, "build.language")?;
if build.standard.trim().is_empty() { let lang_is_asm = match &build.language {
LanguageConfig::One(s) => s.trim().eq_ignore_ascii_case("asm"),
LanguageConfig::Many(v) => v.len() == 1 && v[0].trim().eq_ignore_ascii_case("asm"),
};
if let Some(ref std) = build.standard
&& std.trim().is_empty()
&& !lang_is_asm
{
return Err(ConfigError::Invalid("build.standard is empty".into())); return Err(ConfigError::Invalid("build.standard is empty".into()));
} }
if build.compiler.trim().is_empty() { if build.compiler.trim().is_empty() {
@@ -754,7 +770,9 @@ fn format_toml(value: &Value) -> Result<String, ConfigError> {
} else { } else {
out.push_str(&format!("language = \"{language}\"\n")); out.push_str(&format!("language = \"{language}\"\n"));
} }
out.push_str(&format!("standard = \"{standard}\"\n")); if !standard.is_empty() {
out.push_str(&format!("standard = \"{standard}\"\n"));
}
out.push_str(&format!("compiler = \"{compiler}\"\n")); out.push_str(&format!("compiler = \"{compiler}\"\n"));
let kind = build let kind = build
.get("kind") .get("kind")