11const std = @import ("std" );
22
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 {
44 const yyjson_dep = b .dependency ("yyjson" , .{});
55
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 (.{
715 .root = yyjson_dep .path ("" ),
816 .files = &[_ ][]const u8 {
917 "src/yyjson.c" ,
@@ -13,46 +21,73 @@ fn setupYyJsonDependency(b: *std.Build, exe: *std.Build.Step.Compile) void {
1321 },
1422 });
1523
16- exe .addIncludePath (yyjson_dep .path ("src" ));
24+ lib .addIncludePath (yyjson_dep .path ("src" ));
25+ lib .linkLibC ();
26+
27+ return lib ;
1728}
1829
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 {
2031 const tree_sitter_cpp_dep = b .dependency ("tree_sitter_cpp" , .{});
2132
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 (.{
2342 .root = tree_sitter_cpp_dep .path ("" ),
2443 .files = &[_ ][]const u8 {
2544 "src/parser.c" ,
26- "src/scanner.c" ,
45+ "src/scanner.c" ,
2746 },
2847 .flags = &[_ ][]const u8 {
29- "-std=c11" , // Use C11 for static_assert support
48+ "-std=c11" , // Use C11 for static_assert support
3049 },
3150 });
51+
52+ lib .linkLibC ();
53+
54+ return lib ;
3255}
3356
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+
3566 // Add tree-sitter core from git submodule
36- exe .addCSourceFiles (.{
67+ lib .addCSourceFiles (.{
3768 .root = b .path ("." ),
3869 .files = &[_ ][]const u8 {
39- "thirdparty/tree-sitter/lib/src/lib.c" , // Amalgamated source
70+ "thirdparty/tree-sitter/lib/src/lib.c" , // Amalgamated source
4071 },
4172 .flags = &[_ ][]const u8 {
4273 "-std=c11" ,
4374 },
4475 });
45-
76+
4677 // 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+
5081 // 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 ;
5388}
5489
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 {
5691 const exe = b .addExecutable (.{
5792 .name = "cesium" ,
5893 .root_module = b .createModule (.{
@@ -67,11 +102,11 @@ fn configureExecutable(b: *std.Build, target: std.Build.ResolvedTarget, optimize
67102 "cesium/src/main.cpp" ,
68103 },
69104 .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
72107 "-Wextra" ,
73- "-Wpedantic" ,
74- "-Wno-unused-parameter" , // Clang-specific flag from CMake
108+ "-Wpedantic" ,
109+ "-Wno-unused-parameter" , // Clang-specific flag from CMake
75110 },
76111 });
77112
@@ -84,7 +119,13 @@ fn configureExecutable(b: *std.Build, target: std.Build.ResolvedTarget, optimize
84119
85120fn setupBuildSteps (b : * std.Build , exe : * std.Build.Step.Compile ) void {
86121 // 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 );
88129
89130 // Create a run step
90131 const run_cmd = b .addRunArtifact (exe );
@@ -109,14 +150,18 @@ pub fn build(b: *std.Build) void {
109150 const target = b .standardTargetOptions (.{});
110151 const optimize = b .standardOptimizeOption (.{});
111152
112- // Configure the main executable
113- const exe = configureExecutable (b , target , optimize );
153+ const exe = createCesiumExe (b , target , optimize );
114154
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 );
119165
120- // Setup build steps
121166 setupBuildSteps (b , exe );
122- }
167+ }
0 commit comments