@@ -36,14 +36,17 @@ const Maker = struct {
36
36
}
37
37
38
38
fn init (builder : * std.build.Builder ) ! Maker {
39
- // const commit_hash = @embedFile(".git/refs/heads/master");
40
39
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
+ );
41
44
const config_header = builder .addConfigHeader (
42
45
.{ .style = .blank , .include_path = "build-info.h" },
43
46
.{
44
47
.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 }) ,
47
50
.BUILD_TARGET = try target .allocDescription (builder .allocator ),
48
51
},
49
52
);
@@ -67,12 +70,20 @@ const Maker = struct {
67
70
68
71
fn obj (m : * const Maker , name : []const u8 , src : []const u8 ) * Compile {
69
72
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 );
70
76
if (std .mem .endsWith (u8 , src , ".c" )) {
71
77
o .addCSourceFiles (&.{src }, m .cflags .items );
72
78
o .linkLibC ();
73
79
} else {
74
80
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
+ }
76
87
}
77
88
o .addConfigHeader (m .config_header );
78
89
for (m .include_dirs .items ) | i | o .addIncludePath (.{ .path = i });
@@ -86,8 +97,14 @@ const Maker = struct {
86
97
for (deps ) | d | e .addObject (d );
87
98
for (m .objs .items ) | o | e .addObject (o );
88
99
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
+ }
91
108
e .addConfigHeader (m .config_header );
92
109
m .builder .installArtifact (e );
93
110
e .want_lto = m .enable_lto ;
@@ -109,7 +126,7 @@ pub fn build(b: *std.build.Builder) !void {
109
126
const ggml_alloc = make .obj ("ggml-alloc" , "ggml-alloc.c" );
110
127
const llama = make .obj ("llama" , "llama.cpp" );
111
128
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" );
113
130
const grammar_parser = make .obj ("grammar-parser" , "common/grammar-parser.cpp" );
114
131
const train = make .obj ("train" , "common/train.cpp" );
115
132
0 commit comments