Skip to content

Commit 59a43da

Browse files
committed
zig : try to fix build
1 parent fb74a4e commit 59a43da

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

build.zig

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,32 @@ const Maker = struct {
6565
return m;
6666
}
6767

68-
fn obj(m: *const Maker, name: []const u8, src: []const u8) *Compile {
68+
fn obj(m: *const Maker, name: []const u8, srcs: []const []const u8) *Compile {
6969
const o = m.builder.addObject(.{ .name = name, .target = m.target, .optimize = m.optimize });
7070
if (o.target.getAbi() != .msvc)
7171
o.defineCMacro("_GNU_SOURCE", null);
7272

73-
if (std.mem.endsWith(u8, src, ".c")) {
74-
o.addCSourceFiles(&.{src}, m.cflags.items);
73+
var is_c = true;
74+
for (srcs) |src| {
75+
if (!std.mem.endsWith(u8, src, ".c")) {
76+
is_c = false;
77+
break;
78+
}
79+
}
80+
81+
if (is_c) {
82+
o.addCSourceFiles(srcs, m.cflags.items);
7583
o.linkLibC();
7684
} else {
77-
o.addCSourceFiles(&.{src}, m.cxxflags.items);
85+
o.addCSourceFiles(srcs, m.cxxflags.items);
7886
if (o.target.getAbi() == .msvc) {
7987
o.linkLibC(); // need winsdk + crt
8088
} else {
8189
// linkLibCpp already add (libc++ + libunwind + libc)
8290
o.linkLibCpp();
8391
}
8492
}
93+
8594
for (m.include_dirs.items) |i| o.addIncludePath(.{ .path = i });
8695
o.want_lto = m.enable_lto;
8796
return o;
@@ -111,32 +120,33 @@ pub fn build(b: *std.build.Builder) !void {
111120
var make = try Maker.init(b);
112121
make.enable_lto = b.option(bool, "lto", "Enable LTO optimization, (default: false)") orelse false;
113122

114-
const ggml = make.obj("ggml", "ggml.c");
115-
const sgemm = make.obj("sgemm", "sgemm.cpp");
116-
const ggml_alloc = make.obj("ggml-alloc", "ggml-alloc.c");
117-
const ggml_backend = make.obj("ggml-backend", "ggml-backend.c");
118-
const ggml_quants = make.obj("ggml-quants", "ggml-quants.c");
119-
const unicode = make.obj("unicode", "unicode.cpp");
120-
const unicode_data = make.obj("unicode-data", "unicode-data.cpp");
121-
const llama = make.obj("llama", "llama.cpp");
122-
const buildinfo = make.obj("common", "common/build-info.cpp");
123-
const common = make.obj("common", "common/common.cpp");
124-
const console = make.obj("console", "common/console.cpp");
125-
const sampling = make.obj("sampling", "common/sampling.cpp");
126-
const grammar_parser = make.obj("grammar-parser", "common/grammar-parser.cpp");
127-
const json_schema_to_grammar = make.obj("json-schema-to-grammar", "common/json-schema-to-grammar.cpp");
128-
const train = make.obj("train", "common/train.cpp");
129-
const clip = make.obj("clip", "examples/llava/clip.cpp");
130-
const llava = make.obj("llava", "examples/llava/llava.cpp");
131-
132-
_ = make.exe("main", "examples/main/main.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, json_schema_to_grammar, buildinfo, sampling, console, grammar_parser });
133-
_ = make.exe("quantize", "examples/quantize/quantize.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, json_schema_to_grammar, buildinfo });
134-
_ = make.exe("perplexity", "examples/perplexity/perplexity.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, json_schema_to_grammar, buildinfo });
135-
_ = make.exe("embedding", "examples/embedding/embedding.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, json_schema_to_grammar, buildinfo });
136-
_ = make.exe("finetune", "examples/finetune/finetune.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, json_schema_to_grammar, buildinfo, train });
137-
_ = make.exe("train-text-from-scratch", "examples/train-text-from-scratch/train-text-from-scratch.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, json_schema_to_grammar, buildinfo, train });
138-
139-
const server = make.exe("server", "examples/server/server.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, json_schema_to_grammar, buildinfo, sampling, grammar_parser, clip, llava });
123+
const ggml = make.obj("ggml", "ggml.c");
124+
const sgemm = make.obj("sgemm", "sgemm.cpp");
125+
const ggml_alloc = make.obj("ggml-alloc", "ggml-alloc.c");
126+
const ggml_backend = make.obj("ggml-backend", "ggml-backend.c");
127+
const ggml_quants = make.obj("ggml-quants", "ggml-quants.c");
128+
const unicode = make.obj("unicode", "unicode.cpp");
129+
const unicode_data = make.obj("unicode-data", "unicode-data.cpp");
130+
const llama = make.obj("llama", "llama.cpp");
131+
const common = make.obj("common", "common/build-info.cpp",
132+
"common/common.cpp",
133+
"common/console.cpp",
134+
"common/sampling.cpp",
135+
"common/grammar-parser.cpp",
136+
"common/json-schema-to-grammar.cpp",
137+
"common/train.cpp");
138+
const clip = make.obj("clip", "examples/llava/clip.cpp");
139+
const llava = make.obj("llava", "examples/llava/llava.cpp");
140+
141+
_ = make.exe("main", "examples/main/main.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common });
142+
_ = make.exe("quantize", "examples/quantize/quantize.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common });
143+
_ = make.exe("perplexity", "examples/perplexity/perplexity.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common });
144+
_ = make.exe("embedding", "examples/embedding/embedding.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common });
145+
_ = make.exe("finetune", "examples/finetune/finetune.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common });
146+
147+
_ = make.exe("train-text-from-scratch", "examples/train-text-from-scratch/train-text-from-scratch.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common });
148+
149+
const server = make.exe("server", "examples/server/server.cpp", &.{ ggml, sgemm, ggml_alloc, ggml_backend, ggml_quants, llama, unicode, unicode_data, common, clip, llava });
140150
if (server.target.isWindows()) {
141151
server.linkSystemLibrary("ws2_32");
142152
}

0 commit comments

Comments
 (0)