@@ -47,6 +47,7 @@ const Maker = struct {
47
47
\\char const *LLAMA_BUILD_TARGET = "{s}";
48
48
\\
49
49
, .{ 0 , commit_hash .stdout [0 .. commit_hash .stdout .len - 1 ], zig_version , try target .query .zigTriple (builder .allocator ) }));
50
+
50
51
var m = Maker {
51
52
.builder = builder ,
52
53
.target = target ,
@@ -60,15 +61,20 @@ const Maker = struct {
60
61
61
62
try m .addCFlag ("-std=c11" );
62
63
try m .addCxxFlag ("-std=c++11" );
64
+
65
+ if (m .target .result .abi == .gnu ) {
66
+ try m .addFlag ("-D_GNU_SOURCE" );
67
+ }
68
+ try m .addFlag ("-D_XOPEN_SOURCE=600" );
69
+ try m .addFlag ("-DGGML_USE_VULKAN" );
70
+
63
71
try m .addProjectInclude (&.{});
64
72
try m .addProjectInclude (&.{"common" });
65
73
return m ;
66
74
}
67
75
68
76
fn obj (m : * const Maker , name : []const u8 , src : []const u8 ) * Compile {
69
77
const o = m .builder .addObject (.{ .name = name , .target = m .target , .optimize = m .optimize });
70
- if (m .target .result .abi != .msvc )
71
- o .defineCMacro ("_GNU_SOURCE" , null );
72
78
73
79
if (std .mem .endsWith (u8 , src , ".c" )) {
74
80
o .addCSourceFiles (.{ .files = &.{src }, .flags = m .cflags .items });
@@ -91,7 +97,6 @@ const Maker = struct {
91
97
const e = m .builder .addExecutable (.{ .name = name , .target = m .target , .optimize = m .optimize });
92
98
e .addCSourceFiles (.{ .files = &.{src }, .flags = m .cxxflags .items });
93
99
for (deps ) | d | e .addObject (d );
94
- for (m .objs .items ) | o | e .addObject (o );
95
100
for (m .include_dirs .items ) | i | e .addIncludePath (.{ .path = i });
96
101
97
102
// https://github.com/ziglang/zig/issues/15448
@@ -101,6 +106,7 @@ const Maker = struct {
101
106
// linkLibCpp already add (libc++ + libunwind + libc)
102
107
e .linkLibCpp ();
103
108
}
109
+ e .linkSystemLibrary ("vulkan" );
104
110
m .builder .installArtifact (e );
105
111
e .want_lto = m .enable_lto ;
106
112
return e ;
@@ -121,17 +127,30 @@ pub fn build(b: *std.Build) !void {
121
127
const console = make .obj ("console" , "common/console.cpp" );
122
128
const sampling = make .obj ("sampling" , "common/sampling.cpp" );
123
129
const grammar_parser = make .obj ("grammar-parser" , "common/grammar-parser.cpp" );
124
- const train = make .obj ("train" , "common/train.cpp" );
130
+ // const train = make.obj("train", "common/train.cpp");
125
131
const clip = make .obj ("clip" , "examples/llava/clip.cpp" );
132
+ const ggml_vulkan = make .obj ("ggml-vulkan" , "ggml-vulkan.cpp" );
126
133
127
- _ = make .exe ("main" , "examples/main/main.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo , sampling , console , grammar_parser });
128
- _ = make .exe ("quantize" , "examples/quantize/quantize.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo });
129
- _ = make .exe ("perplexity" , "examples/perplexity/perplexity.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo });
130
- _ = make .exe ("embedding" , "examples/embedding/embedding.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo });
131
- _ = make .exe ("finetune" , "examples/finetune/finetune.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo , train });
132
- _ = make .exe ("train-text-from-scratch" , "examples/train-text-from-scratch/train-text-from-scratch.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo , train });
134
+ _ = make .exe ("main" , "examples/main/main.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo , sampling , console , grammar_parser , ggml_vulkan });
135
+ // _ = make.exe("quantize", "examples/quantize/quantize.cpp", &.{ ggml, ggml_alloc, ggml_backend, ggml_quants, llama, common, buildinfo });
136
+ // _ = make.exe("perplexity", "examples/perplexity/perplexity.cpp", &.{ ggml, ggml_alloc, ggml_backend, ggml_quants, llama, common, buildinfo });
137
+ // _ = make.exe("embedding", "examples/embedding/embedding.cpp", &.{ ggml, ggml_alloc, ggml_backend, ggml_quants, llama, common, buildinfo });
138
+ // _ = make.exe("finetune", "examples/finetune/finetune.cpp", &.{ ggml, ggml_alloc, ggml_backend, ggml_quants, llama, common, buildinfo, train });
139
+ // _ = make.exe("train-text-from-scratch", "examples/train-text-from-scratch/train-text-from-scratch.cpp", &.{ ggml, ggml_alloc, ggml_backend, ggml_quants, llama, common, buildinfo, train });
133
140
134
- const server = make .exe ("server" , "examples/server/server.cpp" , &.{ ggml , ggml_alloc , ggml_backend , ggml_quants , llama , common , buildinfo , sampling , grammar_parser , clip });
141
+ const server = make .exe ("server" , "examples/server/server.cpp" , &.{
142
+ ggml ,
143
+ ggml_alloc ,
144
+ ggml_backend ,
145
+ ggml_quants ,
146
+ llama ,
147
+ common ,
148
+ buildinfo ,
149
+ sampling ,
150
+ grammar_parser ,
151
+ clip ,
152
+ ggml_vulkan ,
153
+ });
135
154
if (make .target .result .os .tag == .windows ) {
136
155
server .linkSystemLibrary ("ws2_32" );
137
156
}
0 commit comments