From b1bdfccd1e3bcff5edf538e5abcaba11bd972c86 Mon Sep 17 00:00:00 2001 From: Overlord Date: Sun, 2 Aug 2026 18:16:58 +0200 Subject: [PATCH] Enhance build options and refactor memory management for configuration parsing --- build.zig | 5 ++++- src/main.zig | 15 +++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/build.zig b/build.zig index 02f0723..a446dbb 100644 --- a/build.zig +++ b/build.zig @@ -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); // diff --git a/src/main.zig b/src/main.zig index 08e0265..e72081a 100644 --- a/src/main.zig +++ b/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;