- `dcr gen` command for IDE integration and build tool support
    - `dcr gen project-info`: Output project metadata as JSON
    - `dcr gen compile-commands`: Generate `compile_commands.json` for clangd and clang-tidy
    - `dcr gen vscode`: Generate VS Code `.vscode/` integration (launch.json, tasks.json, settings.json)
    - `dcr gen clion`: Generate JetBrains CLion `.idea/` integration (run configurations, build targets)
- Full workspace support for all `gen` subcommands
This commit is contained in:
2026-03-19 00:02:04 +08:00
parent 0e93a1aa0f
commit 5f0dca4bb3
28 changed files with 1416 additions and 200 deletions

View File

@@ -14,7 +14,12 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
};
let start_time = Instant::now();
let extensions = source_extensions(ctx.language);
let sources = common::collect_sources(&extensions, ctx.exclude_dirs)?;
let sources = common::collect_sources(
ctx.source_roots,
&extensions,
ctx.exclude_dirs,
ctx.include_paths,
)?;
let obj_dir = Path::new("./target").join(ctx.profile).join("obj");
let objects = build_objects(compiler, &sources, &obj_dir, ctx, "o")?;
@@ -80,17 +85,29 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
pub(crate) fn collect_sources(ctx: &BuildContext) -> Result<Vec<String>, String> {
let extensions = source_extensions(ctx.language);
common::collect_sources(&extensions, ctx.exclude_dirs)
common::collect_sources(
ctx.source_roots,
&extensions,
ctx.exclude_dirs,
ctx.include_paths,
)
}
fn source_extensions(language: &str) -> Vec<&str> {
let lang = language.to_lowercase();
match lang.as_str() {
"c" => vec!["c"],
"c++" | "cpp" | "cxx" => vec!["cpp", "cxx", "cc"],
"asm" => vec!["s", "S", "asm"],
_ => vec!["c"],
let mut out = Vec::new();
for part in language.split('+') {
let lang = part.trim().to_lowercase();
match lang.as_str() {
"c" => out.extend(["c"]),
"c++" | "cpp" | "cxx" => out.extend(["cpp", "cxx", "cc"]),
"asm" => out.extend(["s", "S", "asm"]),
_ => {}
}
}
if out.is_empty() {
out.extend(["c"]);
}
out
}
fn default_flags(profile: &str) -> &'static [&'static str] {
@@ -139,6 +156,9 @@ fn build_objects(
cmd.arg(format!("-std={}", ctx.standard));
}
for flag in default_flags(ctx.profile) {
if ctx.platform.is_some() && *flag == "-march=native" {
continue;
}
cmd.arg(flag);
}
for flag in ctx.cflags {