fix for zig 0.11 version
This commit is contained in:
parent
e6a46b0ed1
commit
7642b434cd
1 changed files with 32 additions and 11 deletions
43
build.zig
43
build.zig
|
@ -2,23 +2,28 @@ const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) void {
|
pub fn build(b: *std.build.Builder) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardReleaseOptions();
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
const want_lto = b.option(bool, "lto", "Want -fLTO");
|
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.want_lto = want_lto;
|
||||||
lib.setTarget(target);
|
|
||||||
lib.setBuildMode(optimize);
|
|
||||||
lib.linkLibCpp();
|
lib.linkLibCpp();
|
||||||
lib.addIncludePath(".");
|
lib.addIncludePath(".");
|
||||||
lib.addIncludePath("examples");
|
lib.addIncludePath("examples");
|
||||||
lib.addCSourceFiles(&.{
|
lib.addCSourceFiles(&.{
|
||||||
"ggml.c",
|
"ggml.c",
|
||||||
}, &.{"-std=c11"});
|
}, &.{"-std=c11"});
|
||||||
|
|
||||||
lib.addCSourceFiles(&.{
|
lib.addCSourceFiles(&.{
|
||||||
"llama.cpp",
|
"llama.cpp",
|
||||||
}, &.{"-std=c++11"});
|
}, &.{"-std=c++11"});
|
||||||
lib.install();
|
|
||||||
|
b.installArtifact(lib);
|
||||||
|
|
||||||
const build_args = .{ .b = b, .lib = lib, .target = target, .optimize = optimize, .want_lto = want_lto };
|
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
|
// create "zig build run" command for ./main
|
||||||
|
|
||||||
const run_cmd = exe.run();
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
|
||||||
if (b.args) |args| {
|
if (b.args) |args| {
|
||||||
run_cmd.addArgs(args);
|
run_cmd.addArgs(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
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 {
|
fn build_example(comptime name: []const u8, args: anytype) *std.build.LibExeObjStep {
|
||||||
const b = args.b;
|
const b = args.b;
|
||||||
|
|
||||||
const lib = args.lib;
|
const lib = args.lib;
|
||||||
const want_lto = args.want_lto;
|
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;
|
exe.want_lto = want_lto;
|
||||||
lib.setTarget(args.target);
|
|
||||||
lib.setBuildMode(args.optimize);
|
|
||||||
exe.addIncludePath(".");
|
exe.addIncludePath(".");
|
||||||
exe.addIncludePath("examples");
|
exe.addIncludePath("examples");
|
||||||
exe.addCSourceFiles(&.{
|
exe.addCSourceFiles(&.{
|
||||||
std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{name, name}),
|
|
||||||
"examples/common.cpp",
|
"examples/common.cpp",
|
||||||
}, &.{"-std=c++11"});
|
}, &.{"-std=c++11"});
|
||||||
|
|
||||||
exe.linkLibrary(lib);
|
exe.linkLibrary(lib);
|
||||||
exe.install();
|
b.installArtifact(exe);
|
||||||
|
|
||||||
return exe;
|
return exe;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue