@@ -3,12 +3,14 @@ const std = @import("std");
3
3
pub fn build (b : * std.Build ) void {
4
4
const target = b .standardTargetOptions (.{});
5
5
const optimize = b .standardOptimizeOption (.{});
6
+ const want_lto = b .option (bool , "lto" , "Want -fLTO" );
6
7
7
8
const lib = b .addStaticLibrary (.{
8
9
.name = "llama" ,
9
10
.target = target ,
10
11
.optimize = optimize ,
11
12
});
13
+ lib .want_lto = want_lto ;
12
14
lib .linkLibCpp ();
13
15
lib .addIncludePath ("." );
14
16
lib .addIncludePath ("examples" );
@@ -17,11 +19,11 @@ pub fn build(b: *std.Build) void {
17
19
}, &.{"-std=c11" });
18
20
lib .addCSourceFiles (&.{
19
21
"llama.cpp" ,
20
- "examples/common.cpp" ,
21
22
}, &.{"-std=c++11" });
22
23
lib .install ();
23
24
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
+
25
27
const exe = build_example ("main" , build_args );
26
28
_ = build_example ("quantize" , build_args );
27
29
_ = build_example ("perplexity" , build_args );
@@ -44,16 +46,19 @@ fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjS
44
46
const lib = args .lib ;
45
47
const target = args .target ;
46
48
const optimize = args .optimize ;
49
+ const want_lto = args .want_lto ;
47
50
48
51
const exe = b .addExecutable (.{
49
52
.name = name ,
50
53
.target = target ,
51
54
.optimize = optimize ,
52
55
});
56
+ exe .want_lto = want_lto ;
53
57
exe .addIncludePath ("." );
54
58
exe .addIncludePath ("examples" );
55
59
exe .addCSourceFiles (&.{
56
60
std .fmt .comptimePrint ("examples/{s}/{s}.cpp" , .{name , name }),
61
+ "examples/common.cpp" ,
57
62
}, &.{"-std=c++11" });
58
63
exe .linkLibrary (lib );
59
64
exe .install ();
0 commit comments