Skip to content

Commit 279a1d7

Browse files
committed
working vulkan zig build
1 parent 16ecbc9 commit 279a1d7

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

build.zig

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const Maker = struct {
4747
\\char const *LLAMA_BUILD_TARGET = "{s}";
4848
\\
4949
, .{ 0, commit_hash.stdout[0 .. commit_hash.stdout.len - 1], zig_version, try target.query.zigTriple(builder.allocator) }));
50+
5051
var m = Maker{
5152
.builder = builder,
5253
.target = target,
@@ -60,15 +61,20 @@ const Maker = struct {
6061

6162
try m.addCFlag("-std=c11");
6263
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+
6371
try m.addProjectInclude(&.{});
6472
try m.addProjectInclude(&.{"common"});
6573
return m;
6674
}
6775

6876
fn obj(m: *const Maker, name: []const u8, src: []const u8) *Compile {
6977
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);
7278

7379
if (std.mem.endsWith(u8, src, ".c")) {
7480
o.addCSourceFiles(.{ .files = &.{src}, .flags = m.cflags.items });
@@ -91,7 +97,6 @@ const Maker = struct {
9197
const e = m.builder.addExecutable(.{ .name = name, .target = m.target, .optimize = m.optimize });
9298
e.addCSourceFiles(.{ .files = &.{src}, .flags = m.cxxflags.items });
9399
for (deps) |d| e.addObject(d);
94-
for (m.objs.items) |o| e.addObject(o);
95100
for (m.include_dirs.items) |i| e.addIncludePath(.{ .path = i });
96101

97102
// https://github.com/ziglang/zig/issues/15448
@@ -101,6 +106,7 @@ const Maker = struct {
101106
// linkLibCpp already add (libc++ + libunwind + libc)
102107
e.linkLibCpp();
103108
}
109+
e.linkSystemLibrary("vulkan");
104110
m.builder.installArtifact(e);
105111
e.want_lto = m.enable_lto;
106112
return e;
@@ -121,17 +127,30 @@ pub fn build(b: *std.Build) !void {
121127
const console = make.obj("console", "common/console.cpp");
122128
const sampling = make.obj("sampling", "common/sampling.cpp");
123129
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");
125131
const clip = make.obj("clip", "examples/llava/clip.cpp");
132+
const ggml_vulkan = make.obj("ggml-vulkan", "ggml-vulkan.cpp");
126133

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 });
133140

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+
});
135154
if (make.target.result.os.tag == .windows) {
136155
server.linkSystemLibrary("ws2_32");
137156
}

0 commit comments

Comments
 (0)