]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
zig : add zig build system support (#279)
authorsjinzh <redacted>
Sat, 24 Jun 2023 17:03:13 +0000 (01:03 +0800)
committerGitHub <redacted>
Sat, 24 Jun 2023 17:03:13 +0000 (20:03 +0300)
* add zig build system support

* add zig build system support

.gitignore
build.zig [new file with mode: 0644]

index 7714dd6febb9149e7a0570f6a75b1e35c1041bfc..093031907516335187d3112ed958cdd11047740f 100644 (file)
@@ -16,3 +16,6 @@ CMakeSettings.json
 
 src/arm_neon.h
 tests/arm_neon.h
+
+zig-out/
+zig-cache/
\ No newline at end of file
diff --git a/build.zig b/build.zig
new file mode 100644 (file)
index 0000000..f32a081
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,57 @@
+const std = @import("std");
+
+// Zig Version: 0.11.0-dev.3379+629f0d23b
+pub fn build(b: *std.build.Builder) void {
+    const target = b.standardTargetOptions(.{});
+    const optimize = b.standardOptimizeOption(.{});
+    const lib = b.addStaticLibrary(.{
+        .name = "ggml",
+        .target = target,
+        .optimize = optimize,
+    });
+    lib.linkLibC();
+    lib.linkLibCpp();
+    lib.addIncludePath(".");
+    lib.addIncludePath("./include");
+    lib.addIncludePath("./include/ggml");
+    lib.addIncludePath("./examples");
+    lib.addCSourceFiles(&.{
+        "src/ggml.c",
+    }, &.{"-std=c11"});
+    b.installArtifact(lib);
+
+    const examples = .{
+        "dolly-v2",
+        "gpt-2",
+        "gpt-j",
+        "gpt-neox",
+        "mnist",
+        "mpt",
+        "replit",
+        "starcoder",
+    };
+
+    inline for (examples) |example_name| {
+        const exe = b.addExecutable(.{
+            .name = example_name,
+            .target = target,
+            .optimize = optimize,
+        });
+        exe.addIncludePath(".");
+        exe.addIncludePath("./include");
+        exe.addIncludePath("./include/ggml");
+        exe.addIncludePath("./examples");
+        exe.addCSourceFiles(&.{
+            std.fmt.comptimePrint("examples/{s}/{s}.cpp", .{example_name, "main"}),
+            "examples/common.cpp",
+            "examples/common-ggml.cpp",
+        }, &.{"-std=c++11"});
+        exe.linkLibrary(lib);
+        b.installArtifact(exe);
+        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_" ++ example_name, "Run the app");
+        run_step.dependOn(&run_cmd.step);
+    }
+}
\ No newline at end of file