Skip to content

Commit c1950c3

Browse files
authored
zig : don't link examples/common.cpp for non-example (abetlen#814)
1 parent 4953e90 commit c1950c3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

build.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ const std = @import("std");
33
pub fn build(b: *std.Build) void {
44
const target = b.standardTargetOptions(.{});
55
const optimize = b.standardOptimizeOption(.{});
6+
const want_lto = b.option(bool, "lto", "Want -fLTO");
67

78
const lib = b.addStaticLibrary(.{
89
.name = "llama",
910
.target = target,
1011
.optimize = optimize,
1112
});
13+
lib.want_lto = want_lto;
1214
lib.linkLibCpp();
1315
lib.addIncludePath(".");
1416
lib.addIncludePath("examples");
@@ -17,11 +19,11 @@ pub fn build(b: *std.Build) void {
1719
}, &.{"-std=c11"});
1820
lib.addCSourceFiles(&.{
1921
"llama.cpp",
20-
"examples/common.cpp",
2122
}, &.{"-std=c++11"});
2223
lib.install();
2324

24-
const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize };
25+
const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize, .want_lto = want_lto };
26+
2527
const exe = build_example("main", build_args);
2628
_ = build_example("quantize", build_args);
2729
_ = build_example("perplexity", build_args);
@@ -44,16 +46,19 @@ fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjS
4446
const lib = args.lib;
4547
const target = args.target;
4648
const optimize = args.optimize;
49+
const want_lto = args.want_lto;
4750

4851
const exe = b.addExecutable(.{
4952
.name = name,
5053
.target = target,
5154
.optimize = optimize,
5255
});
56+
exe.want_lto = want_lto;
5357
exe.addIncludePath(".");
5458
exe.addIncludePath("examples");
5559
exe.addCSourceFiles(&.{
5660
std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{name, name}),
61+
"examples/common.cpp",
5762
}, &.{"-std=c++11"});
5863
exe.linkLibrary(lib);
5964
exe.install();

0 commit comments

Comments
 (0)