summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus C. França <matheus-catarino@hotmail.com>2023-10-08 10:59:20 -0300
committerGitHub <noreply@github.com>2023-10-08 16:59:20 +0300
commiteee42c670e6fa6df9cf17e7ffc319f74cbd81354 (patch)
tree3f3dd41faa5ca608b7ca8e7f73db2023bc186b60
parent8e6716a102e390e930594d51302730184dac83cc (diff)
ci : add Zig CI/CD and fix build (#2996)
* zig CI/CD and fix build Signed-off-by: Matheus Catarino França <matheus-catarino@hotmail.com> * fix build_compiler * ci : remove trailing whitespace --------- Signed-off-by: Matheus Catarino França <matheus-catarino@hotmail.com> Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
-rw-r--r--.github/workflows/zig-build.yml25
-rw-r--r--build.zig31
2 files changed, 49 insertions, 7 deletions
diff --git a/.github/workflows/zig-build.yml b/.github/workflows/zig-build.yml
new file mode 100644
index 00000000..68a698ab
--- /dev/null
+++ b/.github/workflows/zig-build.yml
@@ -0,0 +1,25 @@
+name: Zig CI
+
+on:
+ pull_request:
+ push:
+ branches:
+ - master
+
+jobs:
+ build:
+ strategy:
+ fail-fast: false
+ matrix:
+ runs-on: [ubuntu-latest, macos-latest, windows-latest]
+ runs-on: ${{ matrix.runs-on }}
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ submodules: recursive
+ fetch-depth: 0
+ - uses: goto-bus-stop/setup-zig@v2
+ with:
+ version: 0.11.0
+ - name: Build Summary
+ run: zig build --summary all -freference-trace
diff --git a/build.zig b/build.zig
index b95491e0..c86e4c66 100644
--- a/build.zig
+++ b/build.zig
@@ -36,14 +36,17 @@ const Maker = struct {
}
fn init(builder: *std.build.Builder) !Maker {
- // const commit_hash = @embedFile(".git/refs/heads/master");
const target = builder.standardTargetOptions(.{});
+ const zig_version = @import("builtin").zig_version_string;
+ const commit_hash = try std.ChildProcess.exec(
+ .{ .allocator = builder.allocator, .argv = &.{ "git", "rev-parse", "HEAD" } },
+ );
const config_header = builder.addConfigHeader(
.{ .style = .blank, .include_path = "build-info.h" },
.{
.BUILD_NUMBER = 0,
- .BUILD_COMMIT = "12345", // omit newline
- .BUILD_COMPILER = "Zig 0.11.0",
+ .BUILD_COMMIT = commit_hash.stdout[0 .. commit_hash.stdout.len - 1], // omit newline
+ .BUILD_COMPILER = builder.fmt("Zig {s}", .{zig_version}),
.BUILD_TARGET = try target.allocDescription(builder.allocator),
},
);
@@ -67,12 +70,20 @@ const Maker = struct {
fn obj(m: *const Maker, name: []const u8, src: []const u8) *Compile {
const o = m.builder.addObject(.{ .name = name, .target = m.target, .optimize = m.optimize });
+ if (o.target.getAbi() != .msvc)
+ o.defineCMacro("_GNU_SOURCE", null);
+ o.addConfigHeader(m.config_header);
if (std.mem.endsWith(u8, src, ".c")) {
o.addCSourceFiles(&.{src}, m.cflags.items);
o.linkLibC();
} else {
o.addCSourceFiles(&.{src}, m.cxxflags.items);
- o.linkLibCpp();
+ if (o.target.getAbi() == .msvc) {
+ o.linkLibC(); // need winsdk + crt
+ } else {
+ // linkLibCpp already add (libc++ + libunwind + libc)
+ o.linkLibCpp();
+ }
}
o.addConfigHeader(m.config_header);
for (m.include_dirs.items) |i| o.addIncludePath(.{ .path = i });
@@ -86,8 +97,14 @@ const Maker = struct {
for (deps) |d| e.addObject(d);
for (m.objs.items) |o| e.addObject(o);
for (m.include_dirs.items) |i| e.addIncludePath(.{ .path = i });
- e.linkLibC();
- e.linkLibCpp();
+
+ // https://github.com/ziglang/zig/issues/15448
+ if (e.target.getAbi() == .msvc) {
+ e.linkLibC(); // need winsdk + crt
+ } else {
+ // linkLibCpp already add (libc++ + libunwind + libc)
+ e.linkLibCpp();
+ }
e.addConfigHeader(m.config_header);
m.builder.installArtifact(e);
e.want_lto = m.enable_lto;
@@ -109,7 +126,7 @@ pub fn build(b: *std.build.Builder) !void {
const ggml_alloc = make.obj("ggml-alloc", "ggml-alloc.c");
const llama = make.obj("llama", "llama.cpp");
const common = make.obj("common", "common/common.cpp");
- const console = make.obj("common", "common/console.cpp");
+ const console = make.obj("console", "common/console.cpp");
const grammar_parser = make.obj("grammar-parser", "common/grammar-parser.cpp");
const train = make.obj("train", "common/train.cpp");