Enhance build options and refactor memory management for configuration parsing

This commit is contained in:
2026-08-02 18:16:58 +02:00
parent 84c4158aaa
commit b1bdfccd1e
2 changed files with 11 additions and 9 deletions

View File

@@ -2,7 +2,9 @@ const std = @import("std");
pub fn build(b: *std.Build) void pub fn build(b: *std.Build) void
{ {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{
.default_target = .{ .abi = .musl },
});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const version = getGitVersion(b); 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); exe.root_module.addOptions("build_options", options);
// //

View File

@@ -16,7 +16,7 @@ pub fn main(init: std.process.Init) !void
defer _ = gpa.deinit(); defer _ = gpa.deinit();
defer if (debug) 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; 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.", .description = "A lightweight Zig WebSocket server and mesh routing daemon.",
}); });
var path: []const u8 = undefined;
try parser.addOption("path", .{ try parser.addOption("path", .{
.short = 'p', .short = 'p',
.help = "Configuration-File Path (*.toml)", .help = "Configuration-File Path (*.toml)",
@@ -39,19 +37,19 @@ pub fn main(init: std.process.Init) !void
var result = try parser.parseProcess(init); var result = try parser.parseProcess(init);
if (debug) const path = if (debug) path:
{ {
const tmpPath = result.getString("path") orelse "config/config.toml"; 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 tmpPath = result.getString("path") orelse blk: {
const exe = try std.process.executableDirPathAlloc(io, tmpAllocator); const exe = try std.process.executableDirPathAlloc(io, tmpAllocator);
break :blk try std.Io.Dir.path.join(tmpAllocator, &.{ exe, "config/config.toml" }); 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(); tmpArena.deinit();
@@ -71,6 +69,7 @@ fn run(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !void
std.process.exit(1); std.process.exit(1);
}; };
defer parsed.deinit(); defer parsed.deinit();
allocator.free(path);
const configuration = parsed.value; const configuration = parsed.value;