aboutsummaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authoriacore <74560659+iacore@users.noreply.github.com>2023-04-05 15:06:02 +0000
committerGitHub <noreply@github.com>2023-04-05 18:06:02 +0300
commited1c214e667d58ac442b3c6664831fe0eed2941d (patch)
tree5ee0595f3bb55154ee5c9cbbe4a26062659055e4 /build.zig
parent0c44427df10ee024b4e7ef7bfec56e993daff1db (diff)
zig : add build.zig (#773)
Co-authored-by: Locria Cyber <74560659+locriacyber@users.noreply.github.com>
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig62
1 files changed, 62 insertions, 0 deletions
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..b734608
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,62 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+
+ const lib = b.addStaticLibrary(.{
+ .name = "llama",
+ .target = target,
+ .optimize = optimize,
+ });
+ lib.linkLibCpp();
+ lib.addIncludePath(".");
+ lib.addIncludePath("examples");
+ lib.addCSourceFiles(&.{
+ "ggml.c",
+ }, &.{"-std=c11"});
+ lib.addCSourceFiles(&.{
+ "llama.cpp",
+ "examples/common.cpp",
+ }, &.{"-std=c++11"});
+ lib.install();
+
+ const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize };
+ const exe = build_example("main", build_args);
+ _ = build_example("quantize", build_args);
+ _ = build_example("perplexity", build_args);
+ _ = build_example("embedding", build_args);
+
+ // create "zig build run" command for ./main
+
+ const run_cmd = exe.run();
+ run_cmd.step.dependOn(b.getInstallStep());
+ if (b.args) |args| {
+ run_cmd.addArgs(args);
+ }
+
+ const run_step = b.step("run", "Run the app");
+ run_step.dependOn(&run_cmd.step);
+}
+
+fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjStep {
+ const b = args.b;
+ const lib = args.lib;
+ const target = args.target;
+ const optimize = args.optimize;
+
+ const exe = b.addExecutable(.{
+ .name = name,
+ .target = target,
+ .optimize = optimize,
+ });
+ exe.addIncludePath(".");
+ exe.addIncludePath("examples");
+ exe.addCSourceFiles(&.{
+ std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{name, name}),
+ }, &.{"-std=c++11"});
+ exe.linkLibrary(lib);
+ exe.install();
+
+ return exe;
+}