-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.zig
88 lines (71 loc) · 2.78 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const headless = b.option(bool, "headless", "Build headless webserver") orelse false;
const exe = b.addExecutable(.{
.name = "ava",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
// For some reason, linux binaries are huge. Strip them in release mode.
.strip = optimize != .Debug,
});
b.installArtifact(exe);
const embed: []const []const u8 = &.{
"LICENSE.md",
"src/app/index.html",
"src/app/favicon.ico",
"zig-out/app/main.js",
};
const tokamak = b.dependency("tokamak", .{ .embed = embed });
exe.root_module.addImport("tokamak", tokamak.module("tokamak"));
const fridge = b.dependency("fridge", .{ .bundle = exe.rootModuleTarget().os.tag != .macos });
exe.root_module.addImport("fridge", fridge.module("fridge"));
const options = b.addOptions();
options.addOption(bool, "headless", headless);
exe.root_module.addOptions("options", options);
if (!headless) {
try addWebview(b, exe);
}
try addLlama(b, exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
fn addWebview(b: *std.Build, exe: anytype) !void {
const webview = b.dependency("webview", .{});
exe.linkLibCpp();
exe.addIncludePath(webview.path(""));
exe.addCSourceFile(.{ .file = webview.path("webview.cc"), .flags = &.{ "-std=c++14", "-DWEBVIEW_STATIC" } });
switch (exe.rootModuleTarget().os.tag) {
.macos => exe.linkFramework("WebKit"),
.linux => {
exe.linkSystemLibrary("gtk+-3.0");
exe.linkSystemLibrary("webkit2gtk-4.1");
},
.windows => {
exe.linkSystemLibrary("ole32");
exe.linkSystemLibrary("version");
exe.linkSystemLibrary("shlwapi");
},
else => {},
}
}
fn addLlama(b: *std.Build, exe: anytype) !void {
const target = exe.root_module.resolved_target.?;
const dep = b.dependency("llama_cpp", .{});
const llama_cpp = b.addTranslateC(.{
.root_source_file = dep.path("include/llama.h"),
.target = target,
.optimize = .ReleaseFast,
.link_libc = true,
});
llama_cpp.addIncludePath(dep.path("include"));
llama_cpp.addIncludePath(dep.path("ggml/include"));
const bin = b.dependency(b.fmt("llama_cpp_{s}", .{@tagName(target.result.os.tag)}), .{});
exe.addLibraryPath(bin.path("."));
exe.linkSystemLibrary("llama");
exe.root_module.addImport("llama_cpp", llama_cpp.createModule());
}