1
1
const std = @import ("std" );
2
2
3
- fn setupYyJsonDependency (b : * std.Build , exe : * std.Build.Step.Compile ) void {
3
+ fn createYyjsonLib (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) * std.Build.Step.Compile {
4
4
const yyjson_dep = b .dependency ("yyjson" , .{});
5
5
6
- exe .addCSourceFiles (.{
6
+ const lib = b .addLibrary (.{
7
+ .name = "yyjson" ,
8
+ .root_module = b .createModule (.{
9
+ .target = target ,
10
+ .optimize = optimize ,
11
+ }),
12
+ });
13
+
14
+ lib .addCSourceFiles (.{
7
15
.root = yyjson_dep .path ("" ),
8
16
.files = &[_ ][]const u8 {
9
17
"src/yyjson.c" ,
@@ -13,46 +21,73 @@ fn setupYyJsonDependency(b: *std.Build, exe: *std.Build.Step.Compile) void {
13
21
},
14
22
});
15
23
16
- exe .addIncludePath (yyjson_dep .path ("src" ));
24
+ lib .addIncludePath (yyjson_dep .path ("src" ));
25
+ lib .linkLibC ();
26
+
27
+ return lib ;
17
28
}
18
29
19
- fn setupTreeSitterCppDependency (b : * std.Build , exe : * std.Build.Step.Compile ) void {
30
+ fn createTreeSitterCppLib (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) * std.Build.Step.Compile {
20
31
const tree_sitter_cpp_dep = b .dependency ("tree_sitter_cpp" , .{});
21
32
22
- exe .addCSourceFiles (.{
33
+ const lib = b .addLibrary (.{
34
+ .name = "tree-sitter-cpp" ,
35
+ .root_module = b .createModule (.{
36
+ .target = target ,
37
+ .optimize = optimize ,
38
+ }),
39
+ });
40
+
41
+ lib .addCSourceFiles (.{
23
42
.root = tree_sitter_cpp_dep .path ("" ),
24
43
.files = &[_ ][]const u8 {
25
44
"src/parser.c" ,
26
- "src/scanner.c" ,
45
+ "src/scanner.c" ,
27
46
},
28
47
.flags = &[_ ][]const u8 {
29
- "-std=c11" , // Use C11 for static_assert support
48
+ "-std=c11" , // Use C11 for static_assert support
30
49
},
31
50
});
51
+
52
+ lib .linkLibC ();
53
+
54
+ return lib ;
32
55
}
33
56
34
- fn setupTreeSitterCoreDependency (b : * std.Build , exe : * std.Build.Step.Compile ) void {
57
+ fn createTreeSitterCoreLib (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) * std.Build.Step.Compile {
58
+ const lib = b .addLibrary (.{
59
+ .name = "tree-sitter-core" ,
60
+ .root_module = b .createModule (.{
61
+ .target = target ,
62
+ .optimize = optimize ,
63
+ }),
64
+ });
65
+
35
66
// Add tree-sitter core from git submodule
36
- exe .addCSourceFiles (.{
67
+ lib .addCSourceFiles (.{
37
68
.root = b .path ("." ),
38
69
.files = &[_ ][]const u8 {
39
- "thirdparty/tree-sitter/lib/src/lib.c" , // Amalgamated source
70
+ "thirdparty/tree-sitter/lib/src/lib.c" , // Amalgamated source
40
71
},
41
72
.flags = &[_ ][]const u8 {
42
73
"-std=c11" ,
43
74
},
44
75
});
45
-
76
+
46
77
// Add tree-sitter include paths
47
- exe .addIncludePath (b .path ("thirdparty/tree-sitter/lib/include" ));
48
- exe .addIncludePath (b .path ("thirdparty/tree-sitter/lib/src" ));
49
-
78
+ lib .addIncludePath (b .path ("thirdparty/tree-sitter/lib/include" ));
79
+ lib .addIncludePath (b .path ("thirdparty/tree-sitter/lib/src" ));
80
+
50
81
// Add tree-sitter macros
51
- exe .root_module .addCMacro ("_POSIX_C_SOURCE" , "200112L" );
52
- exe .root_module .addCMacro ("_DEFAULT_SOURCE" , "" );
82
+ lib .root_module .addCMacro ("_POSIX_C_SOURCE" , "200112L" );
83
+ lib .root_module .addCMacro ("_DEFAULT_SOURCE" , "" );
84
+
85
+ lib .linkLibC ();
86
+
87
+ return lib ;
53
88
}
54
89
55
- fn configureExecutable (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) * std.Build.Step.Compile {
90
+ fn createCesiumExe (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) * std.Build.Step.Compile {
56
91
const exe = b .addExecutable (.{
57
92
.name = "cesium" ,
58
93
.root_module = b .createModule (.{
@@ -67,11 +102,11 @@ fn configureExecutable(b: *std.Build, target: std.Build.ResolvedTarget, optimize
67
102
"cesium/src/main.cpp" ,
68
103
},
69
104
.flags = &[_ ][]const u8 {
70
- "-std=c++20" , // CMAKE_CXX_STANDARD 20
71
- "-Wall" , // target_compile_options
105
+ "-std=c++20" , // CMAKE_CXX_STANDARD 20
106
+ "-Wall" , // target_compile_options
72
107
"-Wextra" ,
73
- "-Wpedantic" ,
74
- "-Wno-unused-parameter" , // Clang-specific flag from CMake
108
+ "-Wpedantic" ,
109
+ "-Wno-unused-parameter" , // Clang-specific flag from CMake
75
110
},
76
111
});
77
112
@@ -84,7 +119,13 @@ fn configureExecutable(b: *std.Build, target: std.Build.ResolvedTarget, optimize
84
119
85
120
fn setupBuildSteps (b : * std.Build , exe : * std.Build.Step.Compile ) void {
86
121
// Install the executable
87
- b .installArtifact (exe );
122
+ // b.installArtifact(exe);
123
+ const install = b .addInstallArtifact (exe , .{
124
+ .dest_dir = .{ .override = .{ .custom = "../build/bin" } },
125
+ .pdb_dir = .{ .override = .{ .custom = "../build/bin" } },
126
+ .h_dir = .{ .override = .{ .custom = "../build/include" } },
127
+ });
128
+ b .default_step .dependOn (& install .step );
88
129
89
130
// Create a run step
90
131
const run_cmd = b .addRunArtifact (exe );
@@ -109,14 +150,18 @@ pub fn build(b: *std.Build) void {
109
150
const target = b .standardTargetOptions (.{});
110
151
const optimize = b .standardOptimizeOption (.{});
111
152
112
- // Configure the main executable
113
- const exe = configureExecutable (b , target , optimize );
153
+ const exe = createCesiumExe (b , target , optimize );
114
154
115
- // Setup all dependencies
116
- setupYyJsonDependency (b , exe );
117
- setupTreeSitterCppDependency (b , exe );
118
- setupTreeSitterCoreDependency (b , exe );
155
+ const yyjson_lib = createYyjsonLib (b , target , optimize );
156
+ exe .linkLibrary (yyjson_lib );
157
+ exe .addIncludePath (b .dependency ("yyjson" , .{}).path ("src" ));
158
+
159
+ const tree_sitter_core_lib = createTreeSitterCoreLib (b , target , optimize );
160
+ exe .linkLibrary (tree_sitter_core_lib );
161
+ exe .addIncludePath (b .path ("thirdparty/tree-sitter/lib/include" ));
162
+
163
+ const tree_sitter_cpp_lib = createTreeSitterCppLib (b , target , optimize );
164
+ exe .linkLibrary (tree_sitter_cpp_lib );
119
165
120
- // Setup build steps
121
166
setupBuildSteps (b , exe );
122
- }
167
+ }
0 commit comments