Compare commits

...

2 Commits

3 changed files with 40 additions and 33 deletions

View File

@@ -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);
//

View File

@@ -19,7 +19,7 @@ test "parse zocket config"
const allocator = std.testing.allocator;
const parsed = try parse(io, allocator, "zocket/config.toml");
const parsed = try parse(io, allocator, "config/config.toml");
defer parsed.deinit();
const cfg = parsed.value;

View File

@@ -9,22 +9,19 @@ const args = zocket.deps.args;
pub fn main(init: std.process.Init) !void
{
const debug = builtin.mode == .Debug;
const io = init.io;
if (builtin.mode == .Debug)
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
defer if (debug)
{
var arena: std.heap.DebugAllocator(.{}) = .init;
defer _ = arena.deinit();
if (gpa.detectLeaks() != 0) std.process.exit(1);
};
try run(io, arena.allocator(), "config/config.toml");
}
else
{
var arena = std.heap.ArenaAllocator.init(std.heap.smp_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const allocator = if (debug) gpa.allocator() else std.heap.c_allocator;
var tmpArena = std.heap.ArenaAllocator.init(std.heap.smp_allocator);
var tmpArena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
const tmpAllocator = tmpArena.allocator();
var parser = try args.ArgumentParser.init(tmpAllocator, .{
@@ -40,18 +37,24 @@ pub fn main(init: std.process.Init) !void
var result = try parser.parseProcess(init);
const path = if (debug) path:
{
const tmpPath = result.getString("path") orelse "config/config.toml";
break :path try allocator.dupe(u8, tmpPath);
}
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" });
};
const path = try allocator.dupe(u8, tmpPath);
break :path try allocator.dupe(u8, tmpPath);
};
tmpArena.deinit();
try run(io, allocator, path);
}
}
fn run(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !void
{
@@ -66,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;