Skip to content

Commit a7812d9

Browse files
committed
fix build.zig
1 parent 43001ce commit a7812d9

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

build.zig

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ const Compile = std.Build.Step.Compile;
55
const ConfigHeader = std.Build.Step.ConfigHeader;
66
const Mode = std.builtin.OptimizeMode;
77
const Target = std.Build.ResolvedTarget;
8-
const Mode = std.builtin.OptimizeMode;
9-
const Target = std.Build.ResolvedTarget;
108

119
const Maker = struct {
12-
builder: *std.Build,
13-
target: Target,
1410
builder: *std.Build,
1511
target: Target,
1612
optimize: Mode,
@@ -39,11 +35,9 @@ const Maker = struct {
3935
try m.addCxxFlag(flag);
4036
}
4137

42-
fn init(builder: *std.Build) !Maker {
4338
fn init(builder: *std.Build) !Maker {
4439
const target = builder.standardTargetOptions(.{});
4540
const zig_version = @import("builtin").zig_version_string;
46-
const commit_hash = try std.ChildProcess.run(
4741
const commit_hash = try std.ChildProcess.run(
4842
.{ .allocator = builder.allocator, .argv = &.{ "git", "rev-parse", "HEAD" } },
4943
);
@@ -55,8 +49,6 @@ const Maker = struct {
5549
\\
5650
, .{ 0, commit_hash.stdout[0 .. commit_hash.stdout.len - 1], zig_version, try target.query.zigTriple(builder.allocator) }));
5751

58-
, .{ 0, commit_hash.stdout[0 .. commit_hash.stdout.len - 1], zig_version, try target.query.zigTriple(builder.allocator) }));
59-
6052
var m = Maker{
6153
.builder = builder,
6254
.target = target,
@@ -80,7 +72,6 @@ const Maker = struct {
8072
}
8173
try m.addFlag("-D_XOPEN_SOURCE=600");
8274

83-
8475
if (m.target.result.abi == .gnu) {
8576
try m.addFlag("-D_GNU_SOURCE");
8677
}
@@ -103,12 +94,13 @@ const Maker = struct {
10394
} else {
10495
o.addCSourceFiles(.{ .files = &.{src}, .flags = m.cxxflags.items });
10596
if (m.target.result.abi == .msvc) {
106-
o.addCSourceFiles(.{ .files = &.{src}, .flags = m.cxxflags.items });
107-
if (m.target.result.abi == .msvc) {
108-
o.linkLibC(); // need winsdk + crt
109-
} else {
110-
// linkLibCpp already add (libc++ + libunwind + libc)
111-
o.linkLibCpp();
97+
o.addCSourceFiles(.{ .files = &.{src}, .flags = m.cxxflags.items });
98+
if (m.target.result.abi == .msvc) {
99+
o.linkLibC(); // need winsdk + crt
100+
} else {
101+
// linkLibCpp already add (libc++ + libunwind + libc)
102+
o.linkLibCpp();
103+
}
112104
}
113105
}
114106
for (m.include_dirs.items) |i| o.addIncludePath(.{ .path = i });
@@ -128,27 +120,27 @@ const Maker = struct {
128120

129121
// https://github.com/ziglang/zig/issues/15448
130122
if (m.target.result.abi == .msvc) {
131-
if (m.target.result.abi == .msvc) {
132-
e.linkLibC(); // need winsdk + crt
133-
} else {
134-
// linkLibCpp already add (libc++ + libunwind + libc)
135-
e.linkLibCpp();
136-
}
137-
m.builder.installArtifact(e);
138-
e.want_lto = m.enable_lto;
123+
if (m.target.result.abi == .msvc) {
124+
e.linkLibC(); // need winsdk + crt
125+
} else {
126+
// linkLibCpp already add (libc++ + libunwind + libc)
127+
e.linkLibCpp();
128+
}
129+
m.builder.installArtifact(e);
130+
e.want_lto = m.enable_lto;
139131

140-
const run = m.builder.addRunArtifact(e);
141-
if (m.builder.args) |args| {
142-
run.addArgs(args);
143-
}
144-
const step = m.builder.step(name, std.fmt.allocPrint(m.builder.allocator, "Run the {s} example", .{name}) catch @panic("OOM"));
145-
step.dependOn(&run.step);
132+
const run = m.builder.addRunArtifact(e);
133+
if (m.builder.args) |args| {
134+
run.addArgs(args);
135+
}
136+
const step = m.builder.step(name, std.fmt.allocPrint(m.builder.allocator, "Run the {s} example", .{name}) catch @panic("OOM"));
137+
step.dependOn(&run.step);
146138

147-
return e;
139+
return e;
140+
}
148141
}
149142
};
150143

151-
pub fn build(b: *std.Build) !void {
152144
pub fn build(b: *std.Build) !void {
153145
var make = try Maker.init(b);
154146
make.enable_lto = b.option(bool, "lto", "Enable LTO optimization, (default: false)") orelse false;

0 commit comments

Comments
 (0)