chore: port to latest Zig

This commit is contained in:
LordMZTE 2024-04-14 19:31:34 +02:00
parent 888ee2b86b
commit 67266797d9
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
3 changed files with 18 additions and 20 deletions

View File

@ -1,18 +1,18 @@
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "portingtools",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = mode,
.optimize = optimize,
});
exe.install();
b.installArtifact(exe);
const run_cmd = exe.run();
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);

View File

@ -5,7 +5,7 @@ str: []const u8,
const Self = @This();
pub fn read(reader: anytype, alloc: std.mem.Allocator) !Self {
const strlen = try reader.readIntBig(u32);
const strlen = try reader.readInt(u32, .big);
const str = try alloc.alloc(u8, strlen);
errdefer alloc.free(str);
@ -16,6 +16,6 @@ pub fn read(reader: anytype, alloc: std.mem.Allocator) !Self {
}
pub fn write(self: *const Self, writer: anytype) !void {
try writer.writeIntBig(u32, @intCast(u32, self.str.len));
try writer.writeInt(u32, @intCast(self.str.len), .big);
try writer.writeAll(self.str);
}

View File

@ -3,8 +3,8 @@ const csv_reader = @import("csv_reader.zig");
const StringPacket = @import("StringPacket.zig");
pub const std_options = struct {
pub const log_level = .debug;
pub const std_options = std.Options{
.log_level = .debug,
};
const Mapping = struct {
@ -14,7 +14,7 @@ const Mapping = struct {
fn getAddr(alloc: std.mem.Allocator) !std.net.Address {
const sockpath = try std.fs.path.join(alloc, &.{
std.os.getenv("XDG_RUNTIME_DIR") orelse return error.MissingRuntimeDir,
std.posix.getenv("XDG_RUNTIME_DIR") orelse return error.MissingRuntimeDir,
"portingtools.sock",
});
defer alloc.free(sockpath);
@ -51,14 +51,14 @@ fn map() !void {
const addr = try getAddr(alloc);
const sockfd = try std.os.socket(
std.os.AF.UNIX,
std.os.SOCK.STREAM | std.os.SOCK.CLOEXEC,
const sockfd = try std.posix.socket(
std.posix.AF.UNIX,
std.posix.SOCK.STREAM | std.posix.SOCK.CLOEXEC,
0,
);
defer std.os.closeSocket(sockfd);
defer std.posix.close(sockfd);
try std.os.connect(sockfd, &addr.any, addr.getOsSockLen());
try std.posix.connect(sockfd, &addr.any, addr.getOsSockLen());
const stream = std.net.Stream{ .handle = sockfd };
@ -110,7 +110,7 @@ fn runServer() !void {
std.log.warn("couldn't open renames file: {}, skipping", .{err});
}
var mappings_dir = try std.fs.cwd().openIterableDir("mappings", .{});
var mappings_dir = try std.fs.cwd().openDir("mappings", .{ .iterate = true });
defer mappings_dir.close();
var mappings_iter = mappings_dir.iterate();
@ -146,11 +146,9 @@ fn runServer() !void {
std.log.info("loaded {} mappings", .{mappings.count()});
var server = std.net.StreamServer.init(.{});
defer server.deinit();
const addr = try getAddr(alloc);
try server.listen(addr);
var server = try addr.listen(.{});
defer server.deinit();
std.log.info("listening on {}", .{addr});
while (true) {