@@ -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