Enhance build options and refactor memory management for configuration parsing
This commit is contained in:
@@ -2,7 +2,9 @@ const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void
|
||||
{
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const target = b.standardTargetOptions(.{
|
||||
.default_target = .{ .abi = .musl },
|
||||
});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const version = getGitVersion(b);
|
||||
@@ -44,6 +46,7 @@ pub fn build(b: *std.Build) void
|
||||
}),
|
||||
});
|
||||
|
||||
exe.root_module.link_libc = true;
|
||||
exe.root_module.addOptions("build_options", options);
|
||||
|
||||
//
|
||||
|
||||
15
src/main.zig
15
src/main.zig
@@ -16,7 +16,7 @@ pub fn main(init: std.process.Init) !void
|
||||
defer _ = gpa.deinit();
|
||||
defer if (debug)
|
||||
{
|
||||
if (gpa.detectLeaks()) std.posix.exit(1);
|
||||
if (gpa.detectLeaks() != 0) std.process.exit(1);
|
||||
};
|
||||
|
||||
const allocator = if (debug) gpa.allocator() else std.heap.c_allocator;
|
||||
@@ -30,8 +30,6 @@ pub fn main(init: std.process.Init) !void
|
||||
.description = "A lightweight Zig WebSocket server and mesh routing daemon.",
|
||||
});
|
||||
|
||||
var path: []const u8 = undefined;
|
||||
|
||||
try parser.addOption("path", .{
|
||||
.short = 'p',
|
||||
.help = "Configuration-File Path (*.toml)",
|
||||
@@ -39,19 +37,19 @@ pub fn main(init: std.process.Init) !void
|
||||
|
||||
var result = try parser.parseProcess(init);
|
||||
|
||||
if (debug)
|
||||
const path = if (debug) path:
|
||||
{
|
||||
const tmpPath = result.getString("path") orelse "config/config.toml";
|
||||
path = try allocator.dupe(u8, tmpPath);
|
||||
break :path try allocator.dupe(u8, tmpPath);
|
||||
}
|
||||
else
|
||||
else path:
|
||||
{
|
||||
const tmpPath = result.getString("path") orelse blk: {
|
||||
const exe = try std.process.executableDirPathAlloc(io, tmpAllocator);
|
||||
break :blk try std.Io.Dir.path.join(tmpAllocator, &.{ exe, "config/config.toml" });
|
||||
};
|
||||
path = try allocator.dupe(u8, tmpPath);
|
||||
}
|
||||
break :path try allocator.dupe(u8, tmpPath);
|
||||
};
|
||||
|
||||
tmpArena.deinit();
|
||||
|
||||
@@ -71,6 +69,7 @@ fn run(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !void
|
||||
std.process.exit(1);
|
||||
};
|
||||
defer parsed.deinit();
|
||||
allocator.free(path);
|
||||
|
||||
const configuration = parsed.value;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user