- Workspace support (`[workspace]` with deps ordering)
- `clean --all` for workspace members
Changed:
- Project root discovery for `build/run/clean` (searches parent dirs)
- Workspace paths are excluded from root source scan
- Build output now uses a Cargo-style `Compiling <name> v<version>` line
- Build time now reports total time for the whole build stage (workspace included)
- Cache hits are silent (no compile line when nothing is rebuilt)
- Safer build cache: fingerprints include headers and resolved library files
This commit is contained in:
2026-03-06 21:58:54 +08:00
parent 617ba85442
commit 4ea6267a88
26 changed files with 1123 additions and 213 deletions

View File

@@ -1,7 +1,7 @@
use crate::core::builder::BuildContext;
use crate::platform;
use std::fs;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::Instant;
@@ -15,7 +15,7 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
ctx.compiler
};
let start_time = Instant::now();
let sources = collect_sources(ctx.language)?;
let sources = collect_sources(ctx.language, ctx.exclude_dirs)?;
let obj_dir = Path::new("./target").join(ctx.profile).join("obj");
let objects = build_objects(assembler, &sources, &obj_dir, ctx, "o")?;
@@ -82,10 +82,13 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
}
}
fn collect_sources(language: &str) -> Result<Vec<String>, String> {
pub(crate) fn collect_sources(
language: &str,
exclude_dirs: &[PathBuf],
) -> Result<Vec<String>, String> {
let lang = language.to_lowercase();
let mut sources = Vec::new();
collect_sources_rec("./src", &lang, &mut sources)?;
collect_sources_rec("./src", &lang, &mut sources, exclude_dirs)?;
sources.sort();
if sources.is_empty() {
return Err("No source files found in ./src".to_string());
@@ -93,13 +96,32 @@ fn collect_sources(language: &str) -> Result<Vec<String>, String> {
Ok(sources)
}
fn collect_sources_rec(dir: &str, lang: &str, out: &mut Vec<String>) -> Result<(), String> {
let entries = fs::read_dir(dir).map_err(|err| format!("src dir error: {err}"))?;
fn collect_sources_rec(
dir: &str,
lang: &str,
out: &mut Vec<String>,
exclude_dirs: &[PathBuf],
) -> Result<(), String> {
let dir_path = Path::new(dir);
let full_dir = if dir_path.is_absolute() {
dir_path.to_path_buf()
} else {
std::env::current_dir()
.map_err(|err| format!("src dir error: {err}"))?
.join(dir_path)
};
if is_excluded(&full_dir, exclude_dirs) {
return Ok(());
}
let entries = fs::read_dir(&full_dir).map_err(|err| format!("src dir error: {err}"))?;
for entry in entries {
let entry = entry.map_err(|err| format!("src dir error: {err}"))?;
let path = entry.path();
if path.is_dir() {
collect_sources_rec(&path.to_string_lossy(), lang, out)?;
if is_excluded(&path, exclude_dirs) {
continue;
}
collect_sources_rec(&path.to_string_lossy(), lang, out, exclude_dirs)?;
continue;
}
if !path.is_file() {
@@ -107,7 +129,7 @@ fn collect_sources_rec(dir: &str, lang: &str, out: &mut Vec<String>) -> Result<(
}
let ext_raw = path.extension().and_then(|v| v.to_str()).unwrap_or("");
let ext = ext_raw.to_lowercase();
let file = path.to_string_lossy().to_string();
let file = normalize_source_path(&path);
let allowed = lang == "asm" && (ext == "asm" || (ext == "s" && ext_raw == "s"));
if allowed {
out.push(file);
@@ -116,6 +138,22 @@ fn collect_sources_rec(dir: &str, lang: &str, out: &mut Vec<String>) -> Result<(
Ok(())
}
fn is_excluded(path: &Path, exclude_dirs: &[PathBuf]) -> bool {
exclude_dirs.iter().any(|dir| path.starts_with(dir))
}
fn normalize_source_path(path: &Path) -> String {
if !path.is_absolute() {
return path.to_string_lossy().to_string();
}
if let Ok(base) = std::env::current_dir()
&& let Ok(rel) = path.strip_prefix(&base)
{
return format!("./{}", rel.to_string_lossy());
}
path.to_string_lossy().to_string()
}
fn build_objects(
assembler: &str,
sources: &[String],