fix build.zig

This commit is contained in:
hazelnutcloud 2024-02-26 14:26:15 +08:00
parent 43001ce077
commit a7812d9c6e

View file

@ -5,12 +5,8 @@ const Compile = std.Build.Step.Compile;
const ConfigHeader = std.Build.Step.ConfigHeader; const ConfigHeader = std.Build.Step.ConfigHeader;
const Mode = std.builtin.OptimizeMode; const Mode = std.builtin.OptimizeMode;
const Target = std.Build.ResolvedTarget; const Target = std.Build.ResolvedTarget;
const Mode = std.builtin.OptimizeMode;
const Target = std.Build.ResolvedTarget;
const Maker = struct { const Maker = struct {
builder: *std.Build,
target: Target,
builder: *std.Build, builder: *std.Build,
target: Target, target: Target,
optimize: Mode, optimize: Mode,
@ -39,11 +35,9 @@ const Maker = struct {
try m.addCxxFlag(flag); try m.addCxxFlag(flag);
} }
fn init(builder: *std.Build) !Maker {
fn init(builder: *std.Build) !Maker { fn init(builder: *std.Build) !Maker {
const target = builder.standardTargetOptions(.{}); const target = builder.standardTargetOptions(.{});
const zig_version = @import("builtin").zig_version_string; const zig_version = @import("builtin").zig_version_string;
const commit_hash = try std.ChildProcess.run(
const commit_hash = try std.ChildProcess.run( const commit_hash = try std.ChildProcess.run(
.{ .allocator = builder.allocator, .argv = &.{ "git", "rev-parse", "HEAD" } }, .{ .allocator = builder.allocator, .argv = &.{ "git", "rev-parse", "HEAD" } },
); );
@ -55,8 +49,6 @@ const Maker = struct {
\\ \\
, .{ 0, commit_hash.stdout[0 .. commit_hash.stdout.len - 1], zig_version, try target.query.zigTriple(builder.allocator) })); , .{ 0, commit_hash.stdout[0 .. commit_hash.stdout.len - 1], zig_version, try target.query.zigTriple(builder.allocator) }));
, .{ 0, commit_hash.stdout[0 .. commit_hash.stdout.len - 1], zig_version, try target.query.zigTriple(builder.allocator) }));
var m = Maker{ var m = Maker{
.builder = builder, .builder = builder,
.target = target, .target = target,
@ -80,7 +72,6 @@ const Maker = struct {
} }
try m.addFlag("-D_XOPEN_SOURCE=600"); try m.addFlag("-D_XOPEN_SOURCE=600");
if (m.target.result.abi == .gnu) { if (m.target.result.abi == .gnu) {
try m.addFlag("-D_GNU_SOURCE"); try m.addFlag("-D_GNU_SOURCE");
} }
@ -111,6 +102,7 @@ const Maker = struct {
o.linkLibCpp(); o.linkLibCpp();
} }
} }
}
for (m.include_dirs.items) |i| o.addIncludePath(.{ .path = i }); for (m.include_dirs.items) |i| o.addIncludePath(.{ .path = i });
o.want_lto = m.enable_lto; o.want_lto = m.enable_lto;
if (m.install_libs) m.builder.installArtifact(o); if (m.install_libs) m.builder.installArtifact(o);
@ -146,9 +138,9 @@ const Maker = struct {
return e; return e;
} }
}
}; };
pub fn build(b: *std.Build) !void {
pub fn build(b: *std.Build) !void { pub fn build(b: *std.Build) !void {
var make = try Maker.init(b); var make = try Maker.init(b);
make.enable_lto = b.option(bool, "lto", "Enable LTO optimization, (default: false)") orelse false; make.enable_lto = b.option(bool, "lto", "Enable LTO optimization, (default: false)") orelse false;