feat: update version to 0.6.9 and add packaging for Linux and BSD

- Bump version from 0.6.8 to 0.6.9 in Cargo.toml and Cargo.lock.
- Enhance GitHub Actions workflow to build and publish .deb, .rpm, and Snap packages.
- Implement AUR publishing for both dcr and dcr-bin packages.
- Add support for workspace-only projects in the build system.
- Introduce new `workspace` flag for build and run commands.
- Create snapcraft.yaml for Snap package configuration.
- Update build.rs and related files to handle workspace members and inheritance.
- Modify config handling to support optional package and build configurations.
This commit is contained in:
2026-05-27 23:14:49 +08:00
parent e3c35793ec
commit 8c9dd39503
11 changed files with 760 additions and 207 deletions

View File

@@ -69,7 +69,9 @@ pub fn build(args: &[String]) -> i32 {
if flags.target.is_none() {
let config_path = root.join("dcr.toml");
if let Ok(config) = Config::open(config_path.to_str().unwrap()) {
if let Ok(config) = Config::open(config_path.to_str().unwrap())
&& !config.is_workspace_only()
{
let bt = get_build_string_with_profile(&config, "target", "debug");
if !bt.is_empty() {
flags.target = Some(bt);
@@ -100,6 +102,7 @@ pub fn build(args: &[String]) -> i32 {
flags.target.as_deref(),
flags.force,
flags.verbose,
flags.workspace.as_deref(),
)
}) {
Ok(()) => 0,
@@ -372,8 +375,13 @@ fn get_build_steps_with_profile(
get_build_steps(config, &format!("build.{field}"))
}
fn ensure_target_dirs(items: &[String], profile: &str, target_dir: Option<String>) {
if !items.contains(&"target".to_string()) {
fn ensure_target_dirs(
items: &[String],
profile: &str,
target_dir: Option<String>,
skip_local_target: bool,
) {
if !skip_local_target && !items.contains(&"target".to_string()) {
let _ = fs::create_dir("./target");
}
if let Some(dir) = &target_dir {
@@ -414,8 +422,38 @@ fn build_from_root(
target: Option<&str>,
force: bool,
verbose: bool,
workspace: Option<&str>,
) -> Result<(), String> {
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
if config.is_workspace_only() {
let ws = parse_workspace(&config, profile, target, root)?
.ok_or_else(|| "Workspace root has no members defined".to_string())?;
let members: Vec<_> = if let Some(filter_name) = workspace {
ws.members
.into_iter()
.filter(|m| m.name == filter_name)
.collect()
} else {
ws.members
};
if members.is_empty() {
return Err("No matching workspace members to build".to_string());
}
for member in &members {
build_project_at(
&member.path,
profile,
target,
&[],
force,
verbose,
Some(root),
)?;
}
return Ok(());
}
let project_name = get_config_str(&config, "package.name");
let project_version = get_config_str(&config, "package.version");
@@ -454,20 +492,50 @@ fn build_from_root(
)
);
}
if let Some(workspace) = parse_workspace(&config, profile, build_target.as_deref(), root)? {
build_workspace(&workspace, profile, build_target.as_deref(), force, verbose)?;
let excludes: Vec<std::path::PathBuf> =
workspace.members.iter().map(|m| m.path.clone()).collect();
if let Some(ws) = parse_workspace(&config, profile, build_target.as_deref(), root)? {
if let Some(filter_name) = workspace {
for member in ws.members.iter().filter(|m| m.name == filter_name) {
build_project_at(
&member.path,
profile,
build_target.as_deref(),
&[],
force,
verbose,
Some(root),
)?;
}
} else {
build_workspace(
&ws,
profile,
build_target.as_deref(),
force,
verbose,
Some(root),
)?;
let excludes: Vec<std::path::PathBuf> =
ws.members.iter().map(|m| m.path.clone()).collect();
build_project_at(
root,
profile,
build_target.as_deref(),
&excludes,
force,
verbose,
None,
)?;
}
} else {
build_project_at(
root,
profile,
build_target.as_deref(),
&excludes,
&[],
force,
verbose,
None,
)?;
} else {
build_project_at(root, profile, build_target.as_deref(), &[], force, verbose)?;
}
}
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
@@ -485,9 +553,18 @@ fn build_workspace(
target: Option<&str>,
force: bool,
verbose: bool,
workspace_root: Option<&Path>,
) -> Result<(), String> {
for member in &workspace.members {
build_project_at(&member.path, profile, target, &[], force, verbose)?;
build_project_at(
&member.path,
profile,
target,
&[],
force,
verbose,
workspace_root,
)?;
}
Ok(())
}
@@ -499,6 +576,7 @@ fn build_project_at(
exclude_dirs: &[std::path::PathBuf],
force: bool,
verbose: bool,
workspace_root: Option<&Path>,
) -> Result<(), String> {
with_dir(project_root, || {
check_interrupted()?;
@@ -506,7 +584,22 @@ fn build_project_at(
if !items.contains(&"dcr.toml".to_string()) {
return Err("dcr.toml file not found".to_string());
}
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
let mut config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
// Inherit build fields from workspace root if configured
if let Some(root) = workspace_root {
let has_inherit = config
.get("build.inherit")
.and_then(|v| v.as_bool())
.unwrap_or(false);
if has_inherit {
let root_path = root.join("dcr.toml");
if root_path.is_file() {
let parent_config =
Config::open(&root_path.to_string_lossy()).map_err(|e| e.to_string())?;
config.merge_parent(&parent_config);
}
}
}
let project_name = get_config_str(&config, "package.name");
let project_version = get_config_str(&config, "package.version");
let build_target_config = get_build_string_with_profile(&config, "target", profile);
@@ -598,8 +691,33 @@ fn build_project_at(
let resolved_linker = resolve_tool("DCR_LD", tc_ld.as_deref());
let resolved_archiver = resolve_tool("DCR_AR", tc_ar.as_deref());
let target_dir = build_target.map(|t| format!("target/{t}/{profile}"));
ensure_target_dirs(&items, profile, target_dir);
let target_dir_binding = match workspace_root {
Some(root) => {
let target_str = build_target
.map(normalize_target_os)
.filter(|t| !t.is_empty());
let rel: PathBuf = match target_str {
Some(ref t) => Path::new("target").join(t).join(profile),
None => {
let default_dir = if cfg!(target_os = "linux") {
let arch = std::env::consts::ARCH;
format!("{arch}-unknown-linux-gnu/{profile}")
} else {
profile.to_string()
};
Path::new("target").join(&default_dir)
}
};
root.join(&rel).to_string_lossy().to_string()
}
None => normalize_target(build_target.unwrap_or(""), profile).unwrap_or_default(),
};
let target_dir = if target_dir_binding.is_empty() {
None
} else {
Some(target_dir_binding.clone())
};
ensure_target_dirs(&items, profile, target_dir, workspace_root.is_some());
let deps_table = config.get("dependencies").and_then(|v| v.as_table());
let resolved = resolve_deps(&config, profile, build_target, project_root)?;
@@ -635,7 +753,15 @@ fn build_project_at(
dep_root.display()
));
}
build_project_at(&dep_root, profile, build_target, &[], force, verbose)?;
build_project_at(
&dep_root,
profile,
build_target,
&[],
force,
verbose,
None,
)?;
print!(
"\r{:100}\r {} {} v{}",
"",
@@ -724,7 +850,6 @@ fn build_project_at(
}
}
let target_dir_binding = normalize_target(build_target.unwrap_or(""), profile);
let version_info = parse_version_info(&project_version);
let substitute = |s: &str| -> String {
s.replace("{profile}", profile)
@@ -749,7 +874,11 @@ fn build_project_at(
standard: &build_standard,
cxx_standard: &build_cxx_standard,
target: build_target,
target_dir: target_dir_binding.as_deref(),
target_dir: if target_dir_binding.is_empty() {
None
} else {
Some(target_dir_binding.as_str())
},
kind: normalize_kind(&build_kind),
platform: normalize_platform(&build_platform),
linker: resolved_linker.as_deref(),

View File

@@ -21,6 +21,7 @@ use crate::utils::log::warn;
pub struct BuildRunFlags {
pub profile: String,
pub target: Option<String>,
pub workspace: Option<String>,
pub force: bool,
pub clean: bool,
pub verbose: bool,
@@ -29,6 +30,7 @@ pub struct BuildRunFlags {
pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
let mut profile = PROFILE.to_string();
let mut target = None;
let mut workspace = None;
let mut force = false;
let mut clean = false;
let mut verbose = false;
@@ -52,6 +54,15 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
verbose = true;
continue;
}
if candidate == "workspace" {
if let Some(w) = iter.next() {
workspace = Some(w.clone());
} else {
warn("--workspace requires a value");
return Err(1);
}
continue;
}
if candidate == "target" {
if let Some(t) = iter.next() {
target = Some(t.clone());
@@ -76,6 +87,7 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
Ok(BuildRunFlags {
profile,
target,
workspace,
force,
clean,
verbose,

View File

@@ -24,6 +24,7 @@ use crate::utils::fs::find_project_root;
use crate::utils::fs::with_dir;
use crate::utils::log::error;
use crate::utils::text::{BOLD_GREEN, colored};
use std::path::Path;
use std::process::Command;
fn get_run_cmd(
@@ -82,18 +83,82 @@ pub fn run(args: &[String]) -> i32 {
return 1;
}
};
let flags = match parse_build_run_flags(args) {
Ok(v) => v,
Err(_) => return 1,
};
// Handle workspace-only root: delegate to workspace member
if config.is_workspace_only() {
let ws = match crate::core::workspace::parse_workspace(
&config,
&flags.profile,
flags.target.as_deref(),
&root,
) {
Ok(Some(ws)) => ws,
Ok(None) => {
error("Workspace root has no members defined");
return 1;
}
Err(e) => {
error(&e);
return 1;
}
};
let member = match &flags.workspace {
Some(name) => ws.members.iter().find(|m| m.name == *name),
None => ws.main_member(),
};
let member = match member {
Some(m) => m,
None => {
if let Some(name) = &flags.workspace {
error(&format!("Workspace member '{name}' not found"));
} else {
error("No workspace member to run (set `main = true` on one member)");
}
return 1;
}
};
// Build and run from the member's directory
return match with_dir(&member.path, || {
run_project(&member.path, &flags, Some(root.as_path()))
}) {
Ok(code) => code,
Err(e) => {
error(&e);
1
}
};
}
match run_project(&root, &flags, None) {
Ok(code) => code,
Err(e) => {
error(&e);
1
}
}
}
fn run_project(
root: &Path,
flags: &crate::cli::flags::BuildRunFlags,
workspace_root: Option<&Path>,
) -> Result<i32, String> {
let config =
Config::open(root.join("dcr.toml").to_str().unwrap()).map_err(|err| err.to_string())?;
let project_name: &str = config
.get("package.name")
.and_then(|v| v.as_str())
.unwrap_or("");
let mut flags = match parse_build_run_flags(args) {
Ok(v) => v,
Err(_) => return 1,
};
// If no target specified, use default host target for target-specific config
if flags.target.is_none() {
let mut target = flags.target.clone();
if target.is_none() {
let default_target = if cfg!(target_os = "linux") {
"x86_64-unknown-linux-gnu"
} else if cfg!(target_os = "macos") {
@@ -103,7 +168,7 @@ pub fn run(args: &[String]) -> i32 {
} else {
"unknown"
};
flags.target = Some(default_target.to_string());
target = Some(default_target.to_string());
}
let build_kind = config
@@ -112,25 +177,30 @@ pub fn run(args: &[String]) -> i32 {
.or_else(|| config.get("build.kind").and_then(|v| v.as_str()))
.unwrap_or("");
let normalized_target_dir = flags
.target
.as_ref()
.and_then(|t| crate::cli::build::normalize_target(t, &flags.profile));
let normalized_target_dir = match workspace_root {
Some(wr) => target
.as_ref()
.and_then(|t| crate::cli::build::normalize_target(t, &flags.profile))
.map(|rel| wr.join(&rel).to_string_lossy().to_string()),
None => target
.as_ref()
.and_then(|t| crate::cli::build::normalize_target(t, &flags.profile)),
};
let version = config
.get("package.version")
.and_then(|v| v.as_str())
.unwrap_or("");
let run_cmd = get_run_cmd(&config, &flags.profile, flags.target.as_deref(), version);
let run_cmd = get_run_cmd(&config, &flags.profile, target.as_deref(), version);
let kind = build_kind.trim();
if run_cmd.is_none()
&& (kind == "staticlib" || kind == "sharedlib" || kind == "efi" || kind == "elf")
{
error("Cannot run library build");
return 1;
return Err("Cannot run library build".to_string());
}
let build_status = build(args);
let build_status = build(&args_for_build(flags));
let bin_path = crate::platform::bin_path(
&flags.profile,
project_name,
@@ -140,15 +210,15 @@ pub fn run(args: &[String]) -> i32 {
if let Some(cmd) = run_cmd {
println!("\n {} {}", colored("Running", BOLD_GREEN), cmd);
println!("--------------------------------");
return run_shell(&cmd);
return Ok(run_shell(&cmd));
}
println!("\n {} {}", colored("Running", BOLD_GREEN), bin_path);
println!("--------------------------------");
return run_binary(
return Ok(run_binary(
project_name,
&flags.profile,
normalized_target_dir.as_deref(),
);
));
}
let fallback_code = if let Some(cmd) = run_cmd {
@@ -161,11 +231,27 @@ pub fn run(args: &[String]) -> i32 {
)
};
if fallback_code != 1 {
return fallback_code;
return Ok(fallback_code);
}
error("Fix errors in the code to run the project");
1
Err("Fix errors in the code to run the project".to_string())
}
fn args_for_build(flags: &crate::cli::flags::BuildRunFlags) -> Vec<String> {
let mut args = Vec::new();
args.push(format!("--{}", flags.profile));
if let Some(ref target) = flags.target {
args.push("--target".to_string());
args.push(target.clone());
}
if let Some(ref name) = flags.workspace {
args.push("--workspace".to_string());
args.push(name.clone());
}
if flags.verbose {
args.push("--verbose".to_string());
}
args
}
fn run_shell(cmd: &str) -> i32 {