{"id":51918022,"url":"https://github.com/zfl9/zcdb","last_synced_at":"2026-07-27T14:00:56.228Z","repository":{"id":372065113,"uuid":"1297951392","full_name":"zfl9/zcdb","owner":"zfl9","description":"Generate compile_commands.json for Zig build system","archived":false,"fork":false,"pushed_at":"2026-07-18T16:49:20.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-07-18T18:24:11.987Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zfl9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-07-12T03:35:17.000Z","updated_at":"2026-07-18T16:49:23.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zfl9/zcdb","commit_stats":null,"previous_names":["zfl9/zcdb"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/zfl9/zcdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfl9%2Fzcdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfl9%2Fzcdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfl9%2Fzcdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfl9%2Fzcdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zfl9","download_url":"https://codeload.github.com/zfl9/zcdb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfl9%2Fzcdb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35953520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-27T02:00:06.776Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-27T14:00:55.287Z","updated_at":"2026-07-27T14:00:56.147Z","avatar_url":"https://github.com/zfl9.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZCDB\n\n为 Zig 构建系统生成 `compile_commands.json`，开箱即用，无需额外配置。\n\n## 快速开始\n\n### 1. 添加依赖\n\n\u003e 具体版本见 [Tags](https://github.com/zfl9/zcdb/tags) 页面。\n\n```bash\nzig fetch --save=zcdb https://github.com/zfl9/zcdb/archive/refs/tags/v1.0.0.tar.gz\n```\n\n### 2. 集成到 `build.zig`\n\n```zig\nconst zcdb = @import(\"zcdb\");\n\npub fn build(b: *std.Build) void {\n    // 标准构建选项\n    const target = b.standardTargetOptions(.{});\n    const optimize = b.standardOptimizeOption(.{});\n\n    // 创建 zcdb 实例\n    const zcdb_instance = zcdb.Instance.create(b, .{ .target = target });\n    defer zcdb_instance.finalize();\n\n    // 正常构建逻辑（addExecutable、installArtifact 等）\n}\n```\n\n### 3. 使用\n\n```bash\nzig build -Dcdb=yes    # 生成 compile_commands.json\nzig build -Dcdb=force  # 强制重新生成 compile_commands.json\nzig build cdb-gc       # 清理 compile_commands.json 中源文件已不存在的条目\n```\n\n- 生成的 `compile_commands.json` 以 symlink 形式出现在项目根目录。\n- 不同 target 的编译数据库按 `\u003ctriple\u003e@\u003ccpu\u003e` 隔离存放，互不干扰。\n- `zcdb.Instance.create()` 参数中的 target 将被作为 symlink 目标。\n\n## CLI 选项\n\n| 选项 | 默认 | 说明 |\n|---|---|---|\n| `-Dcdb=no` | 是 | 不生成 |\n| `-Dcdb=yes` | | 增量生成 |\n| `-Dcdb=force` | | 强制重新生成（穿透 Zig 编译缓存） |\n\n## API\n\n### `Instance.create(b, options) → *Instance`\n\n在 configure 阶段早期创建 zcdb 实例。\n\n```zig\npub const CreateOptions = struct {\n    target: std.Build.ResolvedTarget,\n    emit_option_name: []const u8 = \"cdb\",\n    gc_step_name: []const u8 = \"cdb-gc\",\n};\n```\n\n### `instance.finalize()`\n\n为所有 C/C++ 编译步骤注入 `-gen-cdb-fragment-path`。通过 `defer` 调用。\n\n### `instance.get_gc_step() → *std.Build.Step`\n\n获取 GC step，可挂载到自定义 step 链中。\n\n### `require_cflags(b, target) → ?[]const []const u8`\n\n获取 zcdb 所需的编译 flags，若未启用则返回 `null`。用于外部构建系统的集成。\n\n```zig\nif (zcdb.require_cflags(b, target)) |cflags| {\n    // 追加到 CFLAGS/CXXFLAGS\n}\n```\n\n## 已知限制\n\nzcdb 的 `compile_commands.json` 反映的是**最近一次实际触发的 C/C++ 编译记录**，而非当前 `zig build` 的构建上下文。这是因为 Zig 编译缓存可能命中了某个历史构建，此时 `zig cc`/`zig c++` 并未执行，cdb 数据未得到更新，仍然是上一次触发编译时的记录。\n\n解决方法：\n\n- 日常增量开发不受影响（源码不断修改，自然触发增量编译）\n- 若怀疑 cdb 滞后，执行 `zig build -Dcdb=force` 强制触发重新构建\n- 或者删除 `.zig-cache/` 本地缓存目录，再重新构建，获得完全干净的 cdb\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfl9%2Fzcdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzfl9%2Fzcdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfl9%2Fzcdb/lists"}