8000 zig : upgrade build system support (#1981) · Pints-AI/llama.cpp@e65ca7e · GitHub
[go: up one dir, main page]

Skip to content

Commit e65ca7e

Browse files
zig : upgrade build system support (ggml-org#1981)
* upgrade zig build system support * zig : add new line at the end of the file --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
1 parent 5ec8dd5 commit e65ca7e

File tree

1 file changed

+44
-47
lines changed

1 file changed

+44
-47
lines changed

build.zig

Lines changed: 44 additions & 47 deletions
< 6ED1 td data-grid-cell-id="diff-f87bb3596894756629bc39d595fb18d479dc4edf168d93a911cadcb060f10fcc-51-57-1" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,58 @@
11
const std = @import("std");
22

3+
// Zig Version: 0.11.0-dev.3379+629f0d23b
34
pub fn build(b: *std.build.Builder) void {
45
const target = b.standardTargetOptions(.{});
5-
const optimize = b.standardReleaseOptions();
6-
const want_lto = b.option(bool, "lto", "Want -fLTO");
7-
8-
const lib = b.addStaticLibrary("llama", null);
9-
lib.want_lto = want_lto;
10-
lib.setTarget(target);
11-
lib.setBuildMode(optimize);
6+
const optimize = b.standardOptimizeOption(.{});
7+
const lib = b.addStaticLibrary(.{
8+
.name = "llama",
9+
.target = target,
10+
.optimize = optimize,
11+
});
12+
lib.linkLibC();
1213
lib.linkLibCpp();
1314
lib.addIncludePath(".");
14-
lib.addIncludePath("examples");
15+
lib.addIncludePath("./examples");
1516
lib.addCSourceFiles(&.{
1617
"ggml.c",
1718
}, &.{"-std=c11"});
1819
lib.addCSourceFiles(&.{
1920
"llama.cpp",
2021
}, &.{"-std=c++11"});
21-
lib.install();
22-
23-
const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize, .want_lto = want_lto };
24-
25-
const exe = build_example("main", build_args);
26-
_ = build_example("quantize", build_args);
27-
_ = build_example("perplexity", build_args);
28-
_ = build_example("embedding", build_args);
29-
30-
// create "zig build run" command for ./main
31-
32-
const run_cmd = exe.run();
33-
run_cmd.step.dependOn(b.getInstallStep());
34-
if (b.args) |args| {
35-
run_cmd.addArgs(args);
22+
b.installArtifact(lib);
23+
24+
const examples = .{
25+
"main",
26+
"baby-llama",
27+
"embedding",
28+
// "metal",
29+
"perplexity",
30+
"quantize",
31+
"quantize-stats",
32+
"save-load-state",
33+
// "server",
34+
"simple",
35+
"train-text-from-scratch",
36+
};
37+
38+
inline for (examples) |example_name| {
39+
const exe = b.addExecutable(.{
40+
.name = example_name,
41+
.target = target,
42+
.optimize = optimize,
43+
});
44+
exe.addIncludePath(".");
45+
exe.addIncludePath("./examples");
46+
exe.addCSourceFiles(&.{
47+
std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{example_name, example_name}),
48+
"examples/common.cpp",
49+
}, &.{"-std=c++11"});
50+
exe.linkLibrary(lib);
51+
b.installArtifact(exe);
52+
const run_cmd = b.addRunArtifact(exe);
53+
run_cmd.step.dependOn(b.getInstallStep());
54+
if (b.args) |args| run_cmd.addArgs(args);
55+
const run_step = b.step("run_" ++ example_name, "Run the app");
56+
run_step.dependOn(&run_cmd.step);
3657
}
37-
38-
const run_step = b.step("run", "Run the app");
39-
run_step.dependOn(&run_cmd.step);
40-
}
41-
42-
fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjStep {
43-
const b = args.b;
44-
const lib = args.lib;
45-
const want_lto = args.want_lto;
46-
47-
const exe = b.addExecutable(name, null);
48-
exe.want_lto = want_lto;
49-
lib.setTarget(args.target);
50-
lib.setBuildMode(args.optimize);
51-
exe.addIncludePath(".");
52-
exe.addIncludePath("examples");
53-
exe.addCSourceFiles(&.{
54-
std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{name, name}),
55-
"examples/common.cpp",
56-
}, &.{"-std=c++11"});
57-
exe.linkLibrary(lib);
58-
exe.install();
59-
60-
return exe;
6158
}

0 commit comments

Comments
 (0)
0