@@ -34,6 +34,10 @@ pub fn build(b: *std.Build) !void {
34
34
"The compute backend to use." ,
35
35
) orelse ComputeBackend .cpu ;
36
36
37
+ const gen_run = b .addSystemCommand (&.{ "python" , "binding_generator.py" });
38
+ gen_run .addFileArg (b .path ("godot_cpp/gdextension/extension_api.json" ));
39
+ const gen_out = gen_run .addOutputDirectoryArg ("godot-cpp-gen" );
40
+
37
41
// godot-llama-cpp
38
42
const plugin = b .addSharedLibrary (.{
39
43
.name = b .fmt ("{s}-{s}-{s}" , .{ extension_name , triple , @tagName (optimize ) }),
@@ -42,14 +46,16 @@ pub fn build(b: *std.Build) !void {
42
46
});
43
47
b .installArtifact (plugin );
44
48
45
- plugin .addCSourceFiles (.{ .files = try findFilesRecursive (b , "src/" , & cfiles_exts ) });
46
- plugin .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "src/" } });
47
- plugin .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "godot_cpp/gdextension/" } });
48
- plugin .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "godot_cpp/include/" } });
49
- plugin .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "godot_cpp/gen/include" } });
50
- plugin .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "llama.cpp/include" } });
51
- plugin .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "llama.cpp/common" } });
52
- plugin .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "llama.cpp/ggml/include" } });
49
+ plugin .addCSourceFiles (.{ .files = try findFilesRecursive (b , "src" , & cfiles_exts ) });
50
+ plugin .addIncludePath (b .path ("src" ));
51
+ plugin .addIncludePath (b .path ("godot_cpp/gdextension" ));
52
+ plugin .addIncludePath (b .path ("godot_cpp/include" ));
53
+ plugin .addIncludePath (gen_out .path (b , "gen/include" ));
54
+ plugin .addIncludePath (b .path ("llama.cpp/src" ));
55
+ plugin .addIncludePath (b .path ("llama.cpp/include" ));
56
+ plugin .addIncludePath (b .path ("llama.cpp/common" ));
57
+ plugin .addIncludePath (b .path ("llama.cpp/ggml/include" ));
58
+ plugin .addIncludePath (b .path ("llama.cpp/ggml/src" ));
53
59
54
60
// godot-cpp
55
61
const lib_godot = b .addStaticLibrary (.{
@@ -58,26 +64,25 @@ pub fn build(b: *std.Build) !void {
58
64
.optimize = optimize ,
59
65
});
60
66
plugin .linkLibrary (lib_godot );
61
-
62
- b .build_root .handle .access ("godot_cpp/gen" , .{}) catch | e | {
63
- switch (e ) {
64
- error .FileNotFound = > {
65
- _ = try std .process .Child .run (.{
66
- .allocator = b .allocator ,
67
- .argv = &.{ "python" , "binding_generator.py" , "godot_cpp/gdextension/extension_api.json" , "godot_cpp" },
68
- .cwd_dir = b .build_root .handle ,
69
- });
70
- },
71
- else = > {},
72
- }
73
- };
74
67
lib_godot .linkLibCpp ();
75
- lib_godot .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "godot_cpp/gdextension/" } });
76
- lib_godot .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "godot_cpp/include/" } });
77
- lib_godot .addIncludePath (.{ .src_path = .{ .owner = b , .sub_path = "godot_cpp/gen/include" } });
68
+ lib_godot .step .dependOn (& gen_run .step );
69
+
70
+ lib_godot .addIncludePath (b .path ("godot_cpp/gdextension" ));
71
+ lib_godot .addIncludePath (b .path ("godot_cpp/include" ));
72
+ lib_godot .addIncludePath (gen_out .path (b , "gen/include" ));
73
+
74
+ const concat_gen_exe = b .addExecutable (.{
75
+ .name = "concat_gen" ,
76
+ .target = target ,
77
+ .optimize = optimize ,
78
+ .root_source_file = b .path ("tools/concat_files.zig" ),
79
+ });
80
+ var concat_gen_run = b .addRunArtifact (concat_gen_exe );
81
+ concat_gen_run .addDirectoryArg (gen_out .path (b , "gen/src" ));
82
+ const concat_gen_out = concat_gen_run .addOutputFileArg ("gen_concat.cpp" );
78
83
const lib_godot_sources = try findFilesRecursive (b , "godot_cpp/src" , & cfiles_exts );
79
- const lib_godot_gen_sources = try findFilesRecursive ( b , "godot_cpp/gen/src" , & cfiles_exts );
80
- lib_godot .addCSourceFiles (.{ .files = lib_godot_gen_sources , .flags = &.{ "-std=c++17" , "-fno-exceptions" } });
84
+
85
+ lib_godot .addCSourceFile (.{ .file = concat_gen_out , .flags = &.{ "-std=c++17" , "-fno-exceptions" } });
81
86
lib_godot .addCSourceFiles (.{ .files = lib_godot_sources , .flags = &.{ "-std=c++17" , "-fno-exceptions" } });
82
87
83
88
// llama.cpp
@@ -91,18 +96,20 @@ pub fn build(b: *std.Build) !void {
91
96
var base_flags = std .ArrayList ([]const u8 ).init (b .allocator );
92
97
var c_flags = std .ArrayList ([]const u8 ).init (b .allocator );
93
98
var cpp_flags = std .ArrayList ([]const u8 ).init (b .allocator );
94
- var include_paths = std .ArrayList ([] const u8 ).init (b .allocator );
99
+ var include_paths = std .ArrayList (std . Build . LazyPath ).init (b .allocator );
95
100
var system_libs = std .ArrayList ([]const u8 ).init (b .allocator );
96
101
var library_paths = std .ArrayList (std .Build .LazyPath ).init (b .allocator );
97
102
98
103
var sources = std .ArrayList (Source ).init (b .allocator );
99
104
100
105
try c_flags .append ("-std=c11" );
101
- try cpp_flags .append ("-std=c++11 " );
106
+ try cpp_flags .append ("-std=c++17 " );
102
107
try include_paths .appendSlice (&.{
103
- "llama.cpp/include" ,
104
- "llama.cpp/common" ,
105
- "llama.cpp/ggml/include" ,
108
+ b .path ("llama.cpp/src" ),
109
+ b .path ("llama.cpp/include" ),
110
+ b .path ("llama.cpp/common" ),
111
+ b .path ("llama.cpp/ggml/include" ),
112
+ b .path ("llama.cpp/ggml/src" ),
106
113
});
107
114
108
115
switch (target .result .os .tag ) {
@@ -127,13 +134,13 @@ pub fn build(b: *std.Build) !void {
127
134
const expand_metal = b .addExecutable (.{
128
135
.name = "expand_metal" ,
129
136
.target = target ,
130
- .root_source_file = .{ . src_path = .{ . owner = b , . sub_path = "tools/expand_metal.zig" } } ,
137
+ .root_source_file = b . path ( "tools/expand_metal.zig" ) ,
131
138
});
132
139
var run_expand_metal = b .addRunArtifact (expand_metal );
133
140
run_expand_metal .addArg ("--metal-file" );
134
- run_expand_metal .addFileArg (.{ . src_path = .{ . owner = b , . sub_path = "llama.cpp/ggml/src/ggml-metal.metal" } } );
141
+ run_expand_metal .addFileArg (b . path ( "llama.cpp/ggml/src/ggml-metal.metal" ) );
135
142
run_expand_metal .addArg ("--common-file" );
136
- run_expand_metal .addFileArg (.{ . src_path = .{ . owner = b , . sub_path = "llama.cpp/ggml/src/ggml-common.h" } } );
143
+ run_expand_metal .addFileArg (b . path ( "llama.cpp/ggml/src/ggml-common.h" ) );
137
144
run_expand_metal .addArg ("--output-file" );
138
145
const metal_expanded = run_expand_metal .addOutputFileArg ("ggml-metal.metal" );
139
146
const install_metal = b .addInstallFileWithDir (metal_expanded , .lib , "ggml-metal.metal" );
@@ -148,7 +155,7 @@ pub fn build(b: *std.Build) !void {
148
155
149
156
const vk_library_path = b .pathJoin (&.{ vulkan_sdk , "lib" });
150
157
const vk_include_path = b .pathJoin (&.{ vulkan_sdk , "include" });
151
- try include_paths .append (vk_include_path );
158
+ try include_paths .append (std.Build.LazyPath { . cwd_relative = vk_include_path } );
152
159
try library_paths .append (.{ .cwd_relative = vk_library_path });
153
160
try system_libs .append ("vulkan" );
154
161
@@ -195,7 +202,6 @@ pub fn build(b: *std.Build) !void {
195
202
.name = source .name ,
196
203
.target = target ,
197
204
.optimize = optimize ,
198
- .pic = true ,
199
205
});
200
206
lib_llama_cpp .addObject (obj );
201
207
if (source .dependencies ) | deps | {
@@ -206,12 +212,7 @@ pub fn build(b: *std.Build) !void {
206
212
const file = if (source .root ) | root |
207
213
root .path (b , source .source_file )
208
214
else
209
- std.Build.LazyPath {
210
- .src_path = .{
211
- .owner = b ,
212
- .sub_path = source .source_file ,
213
- },
214
- };
215
+ b .path (source .source_file );
215
216
const extension = std .meta .stringToEnum (
216
217
Extension ,
217
218
std .fs .path .extension (source .source_file ),
@@ -225,9 +226,7 @@ pub fn build(b: *std.Build) !void {
225
226
.flags = flags ,
226
227
});
227
228
for (include_paths .items ) | path | {
228
- obj .addIncludePath (.{
229
- .src_path = .{ .owner = b , .sub_path = path },
230
- });
229
+ obj .addIncludePath (path );
231
230
}
232
231
for (system_libs .items ) | lib | {
233
232
obj .linkSystemLibrary (lib );
0 commit comments