Skip to content

Commit

Permalink
zig : don't link examples/common.cpp for non-example (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
iacore authored Apr 7, 2023
1 parent 4953e90 commit c1950c3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const want_lto = b.option(bool, "lto", "Want -fLTO");

const lib = b.addStaticLibrary(.{
.name = "llama",
.target = target,
.optimize = optimize,
});
lib.want_lto = want_lto;
lib.linkLibCpp();
lib.addIncludePath(".");
lib.addIncludePath("examples");
Expand All @@ -17,11 +19,11 @@ pub fn build(b: *std.Build) void {
}, &.{"-std=c11"});
lib.addCSourceFiles(&.{
"llama.cpp",
"examples/common.cpp",
}, &.{"-std=c++11"});
lib.install();

const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize };
const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize, .want_lto = want_lto };

const exe = build_example("main", build_args);
_ = build_example("quantize", build_args);
_ = build_example("perplexity", build_args);
Expand All @@ -44,16 +46,19 @@ fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjS
const lib = args.lib;
const target = args.target;
const optimize = args.optimize;
const want_lto = args.want_lto;

const exe = b.addExecutable(.{
.name = name,
.target = target,
.optimize = optimize,
});
exe.want_lto = want_lto;
exe.addIncludePath(".");
exe.addIncludePath("examples");
exe.addCSourceFiles(&.{
std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{name, name}),
"examples/common.cpp",
}, &.{"-std=c++11"});
exe.linkLibrary(lib);
exe.install();
Expand Down

0 comments on commit c1950c3

Please sign in to comment.