Compare commits
2 Commits
250829e922
...
b1bdfccd1e
| Author | SHA1 | Date | |
|---|---|---|---|
| b1bdfccd1e | |||
| 84c4158aaa |
@@ -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);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ test "parse zocket config"
|
|||||||
|
|
||||||
const allocator = std.testing.allocator;
|
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();
|
defer parsed.deinit();
|
||||||
|
|
||||||
const cfg = parsed.value;
|
const cfg = parsed.value;
|
||||||
|
|||||||
66
src/main.zig
66
src/main.zig
@@ -9,48 +9,51 @@ const args = zocket.deps.args;
|
|||||||
|
|
||||||
pub fn main(init: std.process.Init) !void
|
pub fn main(init: std.process.Init) !void
|
||||||
{
|
{
|
||||||
const io = init.io;
|
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;
|
if (gpa.detectLeaks() != 0) std.process.exit(1);
|
||||||
defer _ = arena.deinit();
|
};
|
||||||
|
|
||||||
try run(io, arena.allocator(), "config/config.toml");
|
const allocator = if (debug) gpa.allocator() else std.heap.c_allocator;
|
||||||
|
|
||||||
|
var tmpArena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
|
||||||
|
const tmpAllocator = tmpArena.allocator();
|
||||||
|
|
||||||
|
var parser = try args.ArgumentParser.init(tmpAllocator, .{
|
||||||
|
.name = "zocket",
|
||||||
|
.version = options.version,
|
||||||
|
.description = "A lightweight Zig WebSocket server and mesh routing daemon.",
|
||||||
|
});
|
||||||
|
|
||||||
|
try parser.addOption("path", .{
|
||||||
|
.short = 'p',
|
||||||
|
.help = "Configuration-File Path (*.toml)",
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
else path:
|
||||||
{
|
{
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.smp_allocator);
|
|
||||||
defer arena.deinit();
|
|
||||||
const allocator = arena.allocator();
|
|
||||||
|
|
||||||
var tmpArena = std.heap.ArenaAllocator.init(std.heap.smp_allocator);
|
|
||||||
const tmpAllocator = tmpArena.allocator();
|
|
||||||
|
|
||||||
var parser = try args.ArgumentParser.init(tmpAllocator, .{
|
|
||||||
.name = "zocket",
|
|
||||||
.version = options.version,
|
|
||||||
.description = "A lightweight Zig WebSocket server and mesh routing daemon.",
|
|
||||||
});
|
|
||||||
|
|
||||||
try parser.addOption("path", .{
|
|
||||||
.short = 'p',
|
|
||||||
.help = "Configuration-File Path (*.toml)",
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = try parser.parseProcess(init);
|
|
||||||
|
|
||||||
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" });
|
||||||
};
|
};
|
||||||
|
break :path try allocator.dupe(u8, tmpPath);
|
||||||
|
};
|
||||||
|
|
||||||
const path = try allocator.dupe(u8, tmpPath);
|
tmpArena.deinit();
|
||||||
|
|
||||||
tmpArena.deinit();
|
try run(io, allocator, path);
|
||||||
|
|
||||||
try run(io, allocator, path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !void
|
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);
|
std.process.exit(1);
|
||||||
};
|
};
|
||||||
defer parsed.deinit();
|
defer parsed.deinit();
|
||||||
|
allocator.free(path);
|
||||||
|
|
||||||
const configuration = parsed.value;
|
const configuration = parsed.value;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user