2023-04-05 17:06:02 +02:00
|
|
|
const std = @import("std");
|
2023-07-14 20:50:58 +02:00
|
|
|
const commit_hash = @embedFile(".git/refs/heads/master");
|
2023-04-05 17:06:02 +02:00
|
|
|
|
2023-07-14 20:50:58 +02:00
|
|
|
// Zig Version: 0.11.0-dev.3986+e05c242cd
|
2023-04-13 15:43:22 +02:00
|
|
|
pub fn build(b: *std.build.Builder) void {
|
2023-04-05 17:06:02 +02:00
|
|
|
const target = b.standardTargetOptions(.{});
|
2023-06-25 07:45:44 +02:00
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2023-07-14 20:50:58 +02:00
|
|
|
|
|
|
|
const config_header = b.addConfigHeader(
|
|
|
|
.{ .style = .blank, .include_path = "build-info.h" },
|
|
|
|
.{
|
|
|
|
.BUILD_NUMBER = 0,
|
|
|
|
.BUILD_COMMIT = commit_hash[0 .. commit_hash.len - 1], // omit newline
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-06-25 07:45:44 +02:00
|
|
|
const lib = b.addStaticLibrary(.{
|
|
|
|
.name = "llama",
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
lib.linkLibC();
|
2023-04-05 17:06:02 +02:00
|
|
|
lib.linkLibCpp();
|
|
|
|
lib.addIncludePath(".");
|
2023-06-25 07:45:44 +02:00
|
|
|
lib.addIncludePath("./examples");
|
2023-07-14 20:50:58 +02:00
|
|
|
lib.addConfigHeader(config_header);
|
|
|
|
lib.addCSourceFiles(&.{"ggml.c"}, &.{"-std=c11"});
|
|
|
|
lib.addCSourceFiles(&.{"llama.cpp"}, &.{"-std=c++11"});
|
2023-06-25 07:45:44 +02:00
|
|
|
b.installArtifact(lib);
|
|
|
|
|
|
|
|
const examples = .{
|
|
|
|
"main",
|
|
|
|
"baby-llama",
|
|
|
|
"embedding",
|
2023-07-14 20:50:58 +02:00
|
|
|
"metal",
|
2023-06-25 07:45:44 +02:00
|
|
|
"perplexity",
|
|
|
|
"quantize",
|
|
|
|
"quantize-stats",
|
|
|
|
"save-load-state",
|
2023-07-14 20:50:58 +02:00
|
|
|
"server",
|
2023-06-25 07:45:44 +02:00
|
|
|
"simple",
|
|
|
|
"train-text-from-scratch",
|
|
|
|
};
|
|
|
|
|
|
|
|
inline for (examples) |example_name| {
|
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
.name = example_name,
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
exe.addIncludePath(".");
|
|
|
|
exe.addIncludePath("./examples");
|
2023-07-14 20:50:58 +02:00
|
|
|
exe.addConfigHeader(config_header);
|
2023-06-25 07:45:44 +02:00
|
|
|
exe.addCSourceFiles(&.{
|
2023-07-14 20:50:58 +02:00
|
|
|
std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{ example_name, example_name }),
|
2023-06-25 07:45:44 +02:00
|
|
|
"examples/common.cpp",
|
|
|
|
}, &.{"-std=c++11"});
|
|
|
|
exe.linkLibrary(lib);
|
|
|
|
b.installArtifact(exe);
|
2023-07-14 20:50:58 +02:00
|
|
|
|
2023-06-25 07:45:44 +02:00
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
if (b.args) |args| run_cmd.addArgs(args);
|
2023-07-14 20:50:58 +02:00
|
|
|
|
|
|
|
const run_step = b.step("run-" ++ example_name, "Run the app");
|
2023-06-25 07:45:44 +02:00
|
|
|
run_step.dependOn(&run_cmd.step);
|
2023-04-05 17:06:02 +02:00
|
|
|
}
|
|
|
|
}
|