Refactor configuration handling and integrate command-line argument parsing with args.zig
This commit is contained in:
24
build.zig
24
build.zig
@@ -5,6 +5,11 @@ pub fn build(b: *std.Build) void
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const version = getGitVersion(b);
|
||||
|
||||
const options = b.addOptions();
|
||||
options.addOption([]const u8, "version", version);
|
||||
|
||||
// deps
|
||||
|
||||
const toml_dep = b.dependency("toml", .{
|
||||
@@ -12,6 +17,11 @@ pub fn build(b: *std.Build) void
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const args_dep = b.dependency("args", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
const mod = b.addModule("zocket", .{
|
||||
@@ -20,6 +30,7 @@ pub fn build(b: *std.Build) void
|
||||
});
|
||||
|
||||
mod.addImport("toml", toml_dep.module("toml"));
|
||||
mod.addImport("args", args_dep.module("args"));
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zocket",
|
||||
@@ -33,6 +44,8 @@ pub fn build(b: *std.Build) void
|
||||
}),
|
||||
});
|
||||
|
||||
exe.root_module.addOptions("build_options", options);
|
||||
|
||||
//
|
||||
|
||||
b.installArtifact(exe);
|
||||
@@ -63,3 +76,14 @@ pub fn build(b: *std.Build) void
|
||||
test_step.dependOn(&run_mod_tests.step);
|
||||
test_step.dependOn(&run_exe_tests.step);
|
||||
}
|
||||
|
||||
fn getGitVersion(b: *std.Build) []const u8
|
||||
{
|
||||
const result = b.runAllowFail(
|
||||
&.{ "git", "describe", "--tags", "--always", "--dirty" },
|
||||
undefined,
|
||||
.inherit,
|
||||
) catch return "0.0.0-unknown";
|
||||
|
||||
return b.dupe(std.mem.trim(u8, result, " \n\r\t"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user