fix for zig 0.11 version

This commit is contained in:
Sigis Dagilis 2023-05-10 08:59:16 +02:00
parent e6a46b0ed1
commit 7642b434cd

View file

@ -2,23 +2,28 @@ const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});
const want_lto = b.option(bool, "lto", "Want -fLTO");
const lib = b.addStaticLibrary("llama", null);
const lib = b.addStaticLibrary(.{
.name = "llama",
.optimize = optimize,
.target = target,
});
lib.want_lto = want_lto;
lib.setTarget(target);
lib.setBuildMode(optimize);
lib.linkLibCpp();
lib.addIncludePath(".");
lib.addIncludePath("examples");
lib.addCSourceFiles(&.{
"ggml.c",
}, &.{"-std=c11"});
lib.addCSourceFiles(&.{
"llama.cpp",
}, &.{"-std=c++11"});
lib.install();
b.installArtifact(lib);
const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize, .want_lto = want_lto };
@ -29,33 +34,49 @@ pub fn build(b: *std.build.Builder) void {
// create "zig build run" command for ./main
const run_cmd = exe.run();
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", "Run the app");
run_step.dependOn(&run_cmd.step);
const run_script_str = &[_][]const u8{
"/bin/sh", "-c",
"./scripts/build-info.sh > build-info.h",
};
const run_script = b.addSystemCommand(run_script_str);
const script_step = b.step("script", "create build-info.h - git version info.");
script_step.dependOn(&run_script.step);
b.default_step.dependOn(script_step);
}
fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjStep {
const b = args.b;
const lib = args.lib;
const want_lto = args.want_lto;
const exe = b.addExecutable(name, null);
const exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = std.fmt.comptimePrint("./examples/{s}/{s}.cpp", .{ name, name }) },
.target = args.target,
.optimize = args.optimize,
});
exe.want_lto = want_lto;
lib.setTarget(args.target);
lib.setBuildMode(args.optimize);
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();
b.installArtifact(exe);
return exe;
}