File tree Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Test, Package, and Release
2+
3+ on :
4+ push :
5+ branches : [main]
6+ tags : ['v*']
7+ pull_request :
8+ branches : [main]
9+ workflow_dispatch :
10+
11+ jobs :
12+ build :
13+ runs-on : ubuntu-latest
14+
15+ steps :
16+ - name : Check out repository
17+ uses : actions/checkout@v4
18+ with :
19+ fetch-depth : 0
20+
21+ - name : Set up Zig
22+ uses : mlugg/setup-zig@v1
23+ with :
24+ version : " master"
25+
26+ - name : Build example
27+ working-directory : ./example
28+ run : zig build cc
29+
30+ - name : Verify compile_commands.json
31+ working-directory : ./example
32+ run : |
33+ if [ ! -f "compile_commands.json" ]; then
34+ echo "error: compile_commands.json not found!"
35+ exit 1
36+ fi
37+
38+ if [ ! -s "compile_commands.json" ]; then
39+ echo "compile_commands.json is empty!"
40+ exit 1
41+ fi
42+
43+ if ! jq empty compile_commands.json 2>/dev/null; then
44+ echo "error: compile_commands.json contains invalid JSON!"
45+ exit 1
46+ fi
47+
48+ echo "compile_commands.json validation passed"
49+
Original file line number Diff line number Diff line change 1+ const std = @import ("std" );
2+ const CompileCommands = @import ("compile_commands" );
3+
4+ pub fn build (b : * std.Build ) ! void {
5+ const target = b .standardTargetOptions (.{});
6+ const optimize = b .standardOptimizeOption (.{});
7+ const flags : []const []const u8 = &.{ "-gen-cdb-fragment-path" , "cdb" };
8+
9+ const example_mod = b .createModule (.{
10+ .target = target ,
11+ .optimize = optimize ,
12+ .link_libc = true ,
13+ });
14+ const example = b .addExecutable (.{
15+ .name = "example" ,
16+ .root_module = example_mod ,
17+ });
18+ example .addCSourceFiles (.{
19+ .root = b .path ("src" ),
20+ .files = &.{"example.c" },
21+ .flags = flags ,
22+ });
23+
24+ const cc_step = b .step ("cc" , "Generate Compile Commands Database" );
25+ const gen_file_step = try CompileCommands .createStep (b , "cdb" , "compile_commands.json" );
26+ gen_file_step .dependOn (& example .step );
27+ cc_step .dependOn (gen_file_step );
28+ }
Original file line number Diff line number Diff line change 1+ .{
2+ .name = .example ,
3+ .version = "0.0.0" ,
4+ .fingerprint = 0x6eec9b9f0a97f862 , // Changing this has security and trust implications.
5+ .minimum_zig_version = "0.15.0-dev.208+8acedfd5b" ,
6+ .dependencies = .{
7+ .compile_commands = .{ .path = "../" },
8+ },
9+ .paths = .{
10+ "build.zig" ,
11+ "build.zig.zon" ,
12+ "src" ,
13+ },
14+ }
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+
3+ int main (void ) { printf ("Hello, World!\n" ); }
You can’t perform that action at this time.
0 commit comments