aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Chraghi <63465728+alichraghi@users.noreply.github.com>2023-07-14 11:50:58 -0700
committerGitHub <noreply@github.com>2023-07-14 21:50:58 +0300
commitde8342423d9600cf6e15455c1a27bae441262b45 (patch)
tree52aaf44c1103729873a7a8ed02e6d4aff735703b
parentc48c525f8711780f3f7c59bf92f1760f38317218 (diff)
build.zig : install config header (#2216)
-rw-r--r--build.zig32
1 files changed, 21 insertions, 11 deletions
diff --git a/build.zig b/build.zig
index 49c159e..2287d2a 100644
--- a/build.zig
+++ b/build.zig
@@ -1,9 +1,19 @@
const std = @import("std");
+const commit_hash = @embedFile(".git/refs/heads/master");
-// Zig Version: 0.11.0-dev.3379+629f0d23b
+// Zig Version: 0.11.0-dev.3986+e05c242cd
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
+
+ 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
+ },
+ );
+
const lib = b.addStaticLibrary(.{
.name = "llama",
.target = target,
@@ -13,24 +23,21 @@ pub fn build(b: *std.build.Builder) void {
lib.linkLibCpp();
lib.addIncludePath(".");
lib.addIncludePath("./examples");
- lib.addCSourceFiles(&.{
- "ggml.c",
- }, &.{"-std=c11"});
- lib.addCSourceFiles(&.{
- "llama.cpp",
- }, &.{"-std=c++11"});
+ lib.addConfigHeader(config_header);
+ lib.addCSourceFiles(&.{"ggml.c"}, &.{"-std=c11"});
+ lib.addCSourceFiles(&.{"llama.cpp"}, &.{"-std=c++11"});
b.installArtifact(lib);
const examples = .{
"main",
"baby-llama",
"embedding",
- // "metal",
+ "metal",
"perplexity",
"quantize",
"quantize-stats",
"save-load-state",
- // "server",
+ "server",
"simple",
"train-text-from-scratch",
};
@@ -43,16 +50,19 @@ pub fn build(b: *std.build.Builder) void {
});
exe.addIncludePath(".");
exe.addIncludePath("./examples");
+ exe.addConfigHeader(config_header);
exe.addCSourceFiles(&.{
- std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{example_name, example_name}),
+ std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{ example_name, example_name }),
"examples/common.cpp",
}, &.{"-std=c++11"});
exe.linkLibrary(lib);
b.installArtifact(exe);
+
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
- const run_step = b.step("run_" ++ example_name, "Run the app");
+
+ const run_step = b.step("run-" ++ example_name, "Run the app");
run_step.dependOn(&run_cmd.step);
}
}