{"id":27182767,"url":"https://github.com/tomcat-42/zig-compile-commands","last_synced_at":"2025-04-09T15:16:54.458Z","repository":{"id":286870396,"uuid":"962828980","full_name":"Tomcat-42/zig-compile-commands","owner":"Tomcat-42","description":"compile_commands.json generation for c projects using zig build","archived":false,"fork":false,"pushed_at":"2025-04-08T19:00:53.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T15:16:50.582Z","etag":null,"topics":["build","c","compile-commands","compile-commands-json","zig","zig-build","zig-build-system"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tomcat-42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2025-04-08T18:27:33.000Z","updated_at":"2025-04-08T19:34:11.000Z","dependencies_parsed_at":"2025-04-08T19:51:59.261Z","dependency_job_id":null,"html_url":"https://github.com/Tomcat-42/zig-compile-commands","commit_stats":null,"previous_names":["tomcat-42/zig-compile-commands"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomcat-42%2Fzig-compile-commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomcat-42%2Fzig-compile-commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomcat-42%2Fzig-compile-commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomcat-42%2Fzig-compile-commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tomcat-42","download_url":"https://codeload.github.com/Tomcat-42/zig-compile-commands/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055271,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["build","c","compile-commands","compile-commands-json","zig","zig-build","zig-build-system"],"created_at":"2025-04-09T15:16:53.699Z","updated_at":"2025-04-09T15:16:54.433Z","avatar_url":"https://github.com/Tomcat-42.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zig compile commands\n\nSimple build module to generate a `compile_commands.json`\nfile from [clang compilation database fragments](https://reviews.llvm.org/D66555) dir.\n\nNote: I will only maintain support for zig master.\n\n## Usage\n\nFetch the package:\n\n```sh\nzig fetch --save=compile_commands git+https://github.com/Tomcat-42/zig-compile-commands\n```\n\nAdd the `-gen-cdb-fragment-path \u003cDIR\u003e` flag to your target. Here \u003cDIR\u003e could be any dir, \nfor example the zig cache:\n\n```zig\nconst flags: []const []const u8 = \u0026.{ \n    \"-std=c23\",\n    \"-Wall\",\n    \"-Wextra\",\n    \"-Werror\",\n    \"-Wpedantic\",\n    \"-fno-strict-aliasing\",\n    \"-gen-cdb-fragment-path\",\n    b.fmt(\"{s}/{s}\", .{ b.cache_root.path.?, \"cdb\" }),\n};\n\nconst mod = b.createModule(.{\n    .target = target,\n    .optimize = optimize,\n    .link_libc = true,\n    .pic = true,\n});\n\nmod.addIncludePath(b.path(\"include\"));\nmod.addCSourceFiles(.{\n    .root = b.path(\"src\"),\n    .files = \u0026.{\"main.c\"},\n    .flags = flags,\n});\n\nconst exe = b.addExecutable(.{\n    .name = \"exe\",\n    .root_module = mod,\n});\n```\n\nNow, create the step. The arguments are the fragments dir(the same that you added to the flags)\nand the resulting `compile_commands.json` path:\n\n```zig\nconst cc_step = b.step(\"cc\", \"Generate Compile Commands Database\");\nconst gen_file_step = try GenCompileCommands.createStep(\n    b,\n    b.fmt(\"{s}/{s}\", .{ b.cache_root.path orelse \"./\", \"cdb\" }),\n    b.fmt(\"{s}/{s}\", .{ b.cache_root.path orelse \"./\", \"compile_commands.json\" }),\n);\ngen_file_step.dependOn(\u0026exe.step);\ncc_step.dependOn(gen_file_step);\n```\n\nFinally, generate the file:\n\n```sh\nzig build cc\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomcat-42%2Fzig-compile-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomcat-42%2Fzig-compile-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomcat-42%2Fzig-compile-commands/lists"}