-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.zig
62 lines (55 loc) · 1.9 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const std = @import("std");
// thanks to github.com/mattnite !!!
const libcurl = @import("src/zig-libcurl/libcurl.zig");
const mbedtls = @import("src/zig-libcurl/zig-mbedtls/mbedtls.zig");
const zlib = @import("src/zig-libcurl/zig-zlib/zlib.zig");
const libssh2 = @import("src/zig-libcurl/zig-libssh2/libssh2.zig");
pub fn build(b: *std.build.Builder) !void {
var target = b.standardTargetOptions(.{});
if (target.isLinux()) {
target.abi = .musl;
}
const optimize = b.standardOptimizeOption(.{});
// thanks to github.com/mattnite !!!
const z = zlib.create(b, target, optimize);
const tls = mbedtls.create(b, target, optimize);
const ssh2 = libssh2.create(b, target, optimize);
tls.link(ssh2.step);
const curllib = try libcurl.create(b, target, optimize);
ssh2.link(curllib.step);
tls.link(curllib.step);
z.link(curllib.step, .{});
const curl = b.createModule(.{
.source_file = .{ .path = "./src/zig-libcurl/src/main.zig" },
});
const exe = b.addExecutable(.{
.name = "chat",
// we added zig code to download models
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.addModule("curl", curl);
// now, here comes the C and C++ stuff for the actual chat client
exe.addIncludePath(.{ .path = "src/llm" });
exe.addCSourceFile(.{
.file = .{ .path = "src/llm/ggml/ggml.c" },
.flags = &.{
"-std=c11",
"-D_POSIX_C_SOURCE=200809L", // for clock_gettime()
"-pthread",
},
});
exe.addCSourceFiles(&.{
"src/llm/chat.cpp",
"src/llm/gptj.cpp",
"src/llm/utils.cpp",
}, &.{ "-std=c++11", "-pthread" });
curllib.link(exe, .{});
exe.linkLibC();
exe.linkLibCpp();
if (exe.target.isWindows()) {
exe.want_lto = false;
}
b.installArtifact(exe);
}