Files
llama.cpp/build.zig
T

69 lines
2.0 KiB
Zig
Raw Normal View History

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