@@ -65,23 +65,32 @@ const Maker = struct {
65
65
return m ;
66
66
}
67
67
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 {
69
69
const o = m .builder .addObject (.{ .name = name , .target = m .target , .optimize = m .optimize });
70
70
if (o .target .getAbi () != .msvc )
71
71
o .defineCMacro ("_GNU_SOURCE" , null );
72
72
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 );
75
83
o .linkLibC ();
76
84
} else {
77
- o .addCSourceFiles (&.{ src } , m .cxxflags .items );
85
+ o .addCSourceFiles (srcs , m .cxxflags .items );
78
86
if (o .target .getAbi () == .msvc ) {
79
87
o .linkLibC (); // need winsdk + crt
80
88
} else {
81
89
// linkLibCpp already add (libc++ + libunwind + libc)
82
90
o .linkLibCpp ();
83
91
}
84
92
}
93
+
85
94
for (m .include_dirs .items ) | i | o .addIncludePath (.{ .path = i });
86
95
o .want_lto = m .enable_lto ;
87
96
return o ;
@@ -111,32 +120,33 @@ pub fn build(b: *std.build.Builder) !void {
111
120
var make = try Maker .init (b );
112
121
make .enable_lto = b .option (bool , "lto" , "Enable LTO optimization, (default: false)" ) orelse false ;
113
122
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 });
140
150
if (server .target .isWindows ()) {
141
151
server .linkSystemLibrary ("ws2_32" );
142
152
}
0 commit comments