Skip to content

Commit eee42c6

Browse files
kassaneggerganov
andauthored
ci : add Zig CI/CD and fix build (#2996)
* zig CI/CD and fix build Signed-off-by: Matheus Catarino França <[email protected]> * fix build_compiler * ci : remove trailing whitespace --------- Signed-off-by: Matheus Catarino França <[email protected]> Co-authored-by: Georgi Gerganov <[email protected]>
1 parent 8e6716a commit eee42c6

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

.github/workflows/zig-build.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Zig CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
runs-on: [ubuntu-latest, macos-latest, windows-latest]
15+
runs-on: ${{ matrix.runs-on }}
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
submodules: recursive
20+
fetch-depth: 0
21+
- uses: goto-bus-stop/setup-zig@v2
22+
with:
23+
version: 0.11.0
24+
- name: Build Summary
25+
run: zig build --summary all -freference-trace

build.zig

+24-7
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ const Maker = struct {
3636
}
3737

3838
fn init(builder: *std.build.Builder) !Maker {
39-
// const commit_hash = @embedFile(".git/refs/heads/master");
4039
const target = builder.standardTargetOptions(.{});
40+
const zig_version = @import("builtin").zig_version_string;
41+
const commit_hash = try std.ChildProcess.exec(
42+
.{ .allocator = builder.allocator, .argv = &.{ "git", "rev-parse", "HEAD" } },
43+
);
4144
const config_header = builder.addConfigHeader(
4245
.{ .style = .blank, .include_path = "build-info.h" },
4346
.{
4447
.BUILD_NUMBER = 0,
45-
.BUILD_COMMIT = "12345", // omit newline
46-
.BUILD_COMPILER = "Zig 0.11.0",
48+
.BUILD_COMMIT = commit_hash.stdout[0 .. commit_hash.stdout.len - 1], // omit newline
49+
.BUILD_COMPILER = builder.fmt("Zig {s}", .{zig_version}),
4750
.BUILD_TARGET = try target.allocDescription(builder.allocator),
4851
},
4952
);
@@ -67,12 +70,20 @@ const Maker = struct {
6770

6871
fn obj(m: *const Maker, name: []const u8, src: []const u8) *Compile {
6972
const o = m.builder.addObject(.{ .name = name, .target = m.target, .optimize = m.optimize });
73+
if (o.target.getAbi() != .msvc)
74+
o.defineCMacro("_GNU_SOURCE", null);
75+
o.addConfigHeader(m.config_header);
7076
if (std.mem.endsWith(u8, src, ".c")) {
7177
o.addCSourceFiles(&.{src}, m.cflags.items);
7278
o.linkLibC();
7379
} else {
7480
o.addCSourceFiles(&.{src}, m.cxxflags.items);
75-
o.linkLibCpp();
81+
if (o.target.getAbi() == .msvc) {
82+
o.linkLibC(); // need winsdk + crt
83+
} else {
84+
// linkLibCpp already add (libc++ + libunwind + libc)
85+
o.linkLibCpp();
86+
}
7687
}
7788
o.addConfigHeader(m.config_header);
7889
for (m.include_dirs.items) |i| o.addIncludePath(.{ .path = i });
@@ -86,8 +97,14 @@ const Maker = struct {
8697
for (deps) |d| e.addObject(d);
8798
for (m.objs.items) |o| e.addObject(o);
8899
for (m.include_dirs.items) |i| e.addIncludePath(.{ .path = i });
89-
e.linkLibC();
90-
e.linkLibCpp();
100+
101+
// https://github.com/ziglang/zig/issues/15448
102+
if (e.target.getAbi() == .msvc) {
103+
e.linkLibC(); // need winsdk + crt
104+
} else {
105+
// linkLibCpp already add (libc++ + libunwind + libc)
106+
e.linkLibCpp();
107+
}
91108
e.addConfigHeader(m.config_header);
92109
m.builder.installArtifact(e);
93110
e.want_lto = m.enable_lto;
@@ -109,7 +126,7 @@ pub fn build(b: *std.build.Builder) !void {
109126
const ggml_alloc = make.obj("ggml-alloc", "ggml-alloc.c");
110127
const llama = make.obj("llama", "llama.cpp");
111128
const common = make.obj("common", "common/common.cpp");
112-
const console = make.obj("common", "common/console.cpp");
129+
const console = make.obj("console", "common/console.cpp");
113130
const grammar_parser = make.obj("grammar-parser", "common/grammar-parser.cpp");
114131
const train = make.obj("train", "common/train.cpp");
115132

0 commit comments

Comments
 (0)