- Incremental builds (object caching by mtime)
- `build.kind` with `staticlib` support
- Custom output directory via `build.target`
This commit is contained in:
2026-02-26 17:03:35 +08:00
parent 9fe2604154
commit 7817834790
19 changed files with 410 additions and 56 deletions

View File

@@ -31,6 +31,7 @@ pub fn build(args: &[String]) -> i32 {
let build_language = get_config_str(&config, "build.language");
let build_standard = get_config_str(&config, "build.standard");
let build_target = get_config_str(&config, "build.target");
let build_kind = get_config_str(&config, "build.kind");
let build_cflags = match get_config_list(&config, "build.cflags") {
Ok(v) => v,
Err(msg) => {
@@ -76,6 +77,7 @@ pub fn build(args: &[String]) -> i32 {
language: &build_language,
standard: &build_standard,
target_dir: normalize_target(&build_target),
kind: normalize_kind(&build_kind),
include_dirs: &resolved.include_dirs,
lib_dirs: &resolved.lib_dirs,
libs: &resolved.libs,
@@ -177,3 +179,8 @@ fn normalize_target(target: &str) -> Option<&str> {
Some(trimmed)
}
}
fn normalize_kind(kind: &str) -> &str {
let trimmed = kind.trim();
if trimmed.is_empty() { "bin" } else { trimmed }
}

View File

@@ -1,12 +1,10 @@
use crate::cli::build::build;
use crate::config::{PROFILE, flags};
use crate::core::config::Config;
use crate::platform;
use crate::core::runner::run_binary;
use crate::utils::fs::check_dir;
use crate::utils::log::{error, warn};
use crate::utils::text::{BOLD_GREEN, colored};
use std::path::Path;
use std::process::Command;
pub fn run(args: &[String]) -> i32 {
let mut active_profile = PROFILE.to_string();
@@ -28,6 +26,10 @@ pub fn run(args: &[String]) -> i32 {
.get("package.name")
.and_then(|v| v.as_str())
.unwrap_or("");
let build_kind = config
.get("build.kind")
.and_then(|v| v.as_str())
.unwrap_or("");
let target_dir = config
.get("build.target")
.and_then(|v| v.as_str())
@@ -49,40 +51,23 @@ pub fn run(args: &[String]) -> i32 {
}
}
if build_kind.trim() == "staticlib" {
error("Cannot run static library");
return 1;
}
let build_status = build(args);
let bin_path = platform::bin_path(&active_profile, project_name, target_dir);
let bin_path = crate::platform::bin_path(&active_profile, project_name, target_dir);
if build_status == 0 {
println!("\n {} {}", colored("Running", BOLD_GREEN), bin_path);
println!("--------------------------------");
return Command::new(bin_path)
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);
return run_binary(project_name, &active_profile, target_dir);
}
if target_dir.is_none()
&& check_dir(Some(&format!("target/{active_profile}")))
.unwrap_or_default()
.contains(&active_profile)
{
warn("Launch of the latest release");
return Command::new(platform::bin_path(
&active_profile,
project_name,
target_dir,
))
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);
}
if target_dir.is_some() && Path::new(&bin_path).exists() {
warn("Launch of the latest release");
return Command::new(bin_path)
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);
let fallback_code = run_binary(project_name, &active_profile, target_dir);
if fallback_code != 1 {
return fallback_code;
}
error("Fix errors in the code to run the project");
0
1
}