~leon_plickat/public-inbox

[PATCH upgrade to Zig 0.13.0 3/7] build: cleanup migration to Zig 0.13.0

Details
Message ID
<20240625125718.32012-4-contact@uncomfyhalomacro.pl>
DKIM signature
pass
Download raw message
Patch: +50 -48
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl>
---
 src/Config.zig             | 10 +++++-----
 src/Frontend.zig           |  4 ++--
 src/SecretBuffer.zig       |  8 ++++----
 src/TTY.zig                |  6 +++---
 src/Wayland.zig            | 28 ++++++++++++++--------------
 src/ini.zig                |  2 +-
 src/wayprompt-cli.zig      | 19 +++++++++----------
 src/wayprompt-pinentry.zig | 21 ++++++++++++---------
 8 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/src/Config.zig b/src/Config.zig
index 05a2602..d854ef3 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -1,7 +1,7 @@
const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const os = std.os;
const posix = std.posix;
const fmt = std.fmt;
const meta = std.meta;
const math = std.math;
@@ -105,7 +105,7 @@ const WaylandUi = struct {
                switch (@TypeOf(@field(self, field.name))) {
                    u31, u15 => {
                        @field(self, field.name) = fmt.parseInt(@TypeOf(@field(self, field.name)), value, 10) catch |err| {
                            log.err("{s}:{}: Invalid positive integer: '{s}', {}", .{ path, line, value, err });
                            log.err("{s}:{}: Invalid pposixitive integer: '{s}', {}", .{ path, line, value, err });
                            return error.BadConfig;
                        };
                    },
@@ -162,7 +162,7 @@ pub fn reset(self: *Config, alloc: mem.Allocator) void {
pub fn parse(self: *Config, alloc: mem.Allocator) !void {
    const path = try getConfigPath(alloc);
    defer alloc.free(path);
    os.access(path, os.R_OK) catch return;
    posix.access(path, posix.R_OK) catch return;

    const file = try fs.cwd().openFile(path, .{});
    defer file.close();
@@ -203,12 +203,12 @@ pub fn parse(self: *Config, alloc: mem.Allocator) !void {
}

fn getConfigPath(alloc: mem.Allocator) ![]const u8 {
    if (os.getenv("XDG_CONFIG_HOME")) |xdg_config_home| {
    if (posix.getenv("XDG_CONFIG_HOME")) |xdg_config_home| {
        return try fs.path.join(alloc, &[_][]const u8{
            xdg_config_home,
            "wayprompt/config.ini",
        });
    } else if (os.getenv("HOME")) |home| {
    } else if (posix.getenv("HOME")) |home| {
        return try fs.path.join(alloc, &[_][]const u8{
            home,
            ".config/wayprompt/config.ini",
diff --git a/src/Frontend.zig b/src/Frontend.zig
index a005d06..990e65e 100644
--- a/src/Frontend.zig
+++ b/src/Frontend.zig
@@ -1,6 +1,6 @@
const std = @import("std");
const mem = std.mem;
const os = std.os;
const posix = std.posix;
const log = std.log.scoped(.frontend);

const pixman = @import("pixman");
@@ -32,7 +32,7 @@ const Implementation = union(enum) {

impl: Implementation = undefined,

pub fn init(self: *Frontend, cfg: *Config) !os.fd_t {
pub fn init(self: *Frontend, cfg: *Config) !posix.fd_t {

    // First we try to do a Wayland.
    self.impl = .{ .wayland = .{} };
diff --git a/src/SecretBuffer.zig b/src/SecretBuffer.zig
index 13c7e29..d3955f6 100644
--- a/src/SecretBuffer.zig
+++ b/src/SecretBuffer.zig
@@ -3,7 +3,7 @@ const std = @import("std");
const ascii = std.ascii;
const heap = std.heap;
const mem = std.mem;
const os = std.os;
const posix = std.posix;
const unicode = std.unicode;

const Self = @This();
@@ -27,7 +27,7 @@ pub fn init(self: *Self, alloc: mem.Allocator) !void {
        var attempts: usize = 0;
        while (attempts < 10) : (attempts += 1) {
            const res = mlock(self.buffer.ptr, self.buffer.len);
            switch (os.errno(res)) {
            switch (posix.errno(res)) {
                .SUCCESS => break,
                .AGAIN => continue,
                else => return error.UnexpectedError,
@@ -41,8 +41,8 @@ pub fn init(self: *Self, alloc: mem.Allocator) !void {
    if (builtin.target.os.tag == .linux) {
        var attempts: usize = 0;
        while (attempts < 10) : (attempts += 1) {
            const res = os.system.madvise(self.buffer.ptr, self.buffer.len, os.MADV.DONTDUMP);
            switch (os.errno(res)) {
            const res = posix.system.madvise(self.buffer.ptr, self.buffer.len, posix.MADV.DONTDUMP);
            switch (posix.errno(res)) {
                .SUCCESS => break,
                .AGAIN => continue,
                else => return error.UnexpectedError,
diff --git a/src/TTY.zig b/src/TTY.zig
index cb6eb3b..0fcffb9 100644
--- a/src/TTY.zig
+++ b/src/TTY.zig
@@ -1,6 +1,6 @@
const std = @import("std");
const debug = std.debug;
const os = std.os;
const posix = std.posix;
const io = std.io;
const math = std.math;
const unicode = std.unicode;
@@ -42,7 +42,7 @@ term: spoon.Term = undefined,
config: *Config = undefined,
mode: Frontend.InterfaceMode = .none,

pub fn init(self: *TTY, cfg: *Config) !os.fd_t {
pub fn init(self: *TTY, cfg: *Config) !posix.fd_t {
    self.config = cfg;

    // Only try to fall back to TTY mode when a TTY is set.
@@ -189,7 +189,7 @@ fn renderContent(self: *TTY, rc: *spoon.Term.RenderContext, str: []const u8, att
}

fn renderButton(self: *TTY, rc: *spoon.Term.RenderContext, comptime button: []const u8, str: []const u8, line: *usize) !void {
    var first = line.*;
    const first = line.*;
    try rc.setAttribute(.{});
    try rc.moveCursorTo(line.*, 0);
    var it = LineIterator.from(str);
diff --git a/src/Wayland.zig b/src/Wayland.zig
index f8231c4..8471d8c 100644
--- a/src/Wayland.zig
+++ b/src/Wayland.zig
@@ -1,7 +1,7 @@
const builtin = @import("builtin");
const std = @import("std");
const ascii = std.ascii;
const os = std.os;
const posix = std.posix;
const mem = std.mem;
const math = std.math;
const unicode = std.unicode;
@@ -429,16 +429,16 @@ const Seat = struct {
    fn keyboardListener(_: *wl.Keyboard, event: wl.Keyboard.Event, self: *Seat) void {
        switch (event) {
            .keymap => |ev| {
                defer os.close(ev.fd);
                defer posix.close(ev.fd);
                if (ev.format != .xkb_v1) {
                    self.w.abort(error.UnsupportedKeyboardLayoutFormat);
                    return;
                }
                const keymap_str = os.mmap(null, ev.size, os.PROT.READ, os.MAP.PRIVATE, ev.fd, 0) catch {
                const keymap_str = posix.mmap(null, ev.size, posix.PROT.READ, posix.MAP{ .TYPE = std.os.linux.MAP_TYPE.PRIVATE }, ev.fd, 0) catch {
                    self.w.abort(error.OutOfMemory);
                    return;
                };
                defer os.munmap(keymap_str);
                defer posix.munmap(keymap_str);
                const keymap = xkb.Keymap.newFromBuffer(
                    self.w.xkb_context.?,
                    keymap_str.ptr,
@@ -1255,22 +1255,22 @@ const Buffer = struct {

        const fd = blk: {
            if (builtin.target.os.tag == .linux) {
                break :blk try os.memfd_createZ("/wayprompt", os.linux.MFD.CLOEXEC);
                break :blk try posix.memfd_createZ("/wayprompt", std.os.linux.MFD.CLOEXEC);
            }
            @compileError("patches welcome");
        };
        defer os.close(fd);
        try os.ftruncate(fd, size);
        defer posix.close(fd);
        try posix.ftruncate(fd, size);

        const data = mem.bytesAsSlice(u8, try os.mmap(
        const data = mem.bytesAsSlice(u8, try posix.mmap(
            null,
            size,
            os.PROT.READ | os.PROT.WRITE,
            os.MAP.SHARED,
            posix.PROT.READ | posix.PROT.WRITE,
            posix.MAP{ .TYPE = std.os.linux.MAP_TYPE.SHARED },
            fd,
            0,
        ));
        errdefer os.munmap(data);
        errdefer posix.munmap(data);

        const shm_pool = try w.shm.?.createPool(fd, size);
        defer shm_pool.destroy();
@@ -1300,7 +1300,7 @@ const Buffer = struct {
    fn deinit(self: Buffer) void {
        if (self.pixman_image) |p| _ = p.unref();
        if (self.wl_buffer) |wb| wb.destroy();
        if (self.data) |d| os.munmap(d);
        if (self.data) |d| posix.munmap(d);
    }

    fn bufferListener(_: *wl.Buffer, event: wl.Buffer.Event, self: *Buffer) void {
@@ -1345,12 +1345,12 @@ xkb_context: ?*xkb.Context = undefined,

exit_reason: ?anyerror = null,

pub fn init(self: *Wayland, cfg: *Config) !os.fd_t {
pub fn init(self: *Wayland, cfg: *Config) !posix.fd_t {
    self.config = cfg;

    const wayland_display = blk: {
        if (cfg.wayland_display) |wd| break :blk wd;
        if (os.getenv("WAYLAND_DISPLAY")) |wd| break :blk wd;
        if (posix.getenv("WAYLAND_DISPLAY")) |wd| break :blk wd;
        return error.NoWaylandDisplay;
    };
    log.debug("trying to connect to '{s}'.", .{wayland_display});
diff --git a/src/ini.zig b/src/ini.zig
index 2b2e6b9..8e22d7e 100644
--- a/src/ini.zig
+++ b/src/ini.zig
@@ -52,7 +52,7 @@ fn IniTok(comptime T: type) type {
                    }

                    // Is this line an assignment?
                    var eq_pos = blk: {
                    const eq_pos = blk: {
                        for (buf, 0..) |char, i| {
                            if (char == '=') {
                                if (i == buf.len - 1) return error.InvalidLine;
diff --git a/src/wayprompt-cli.zig b/src/wayprompt-cli.zig
index 8705528..98c2a04 100644
--- a/src/wayprompt-cli.zig
+++ b/src/wayprompt-cli.zig
@@ -1,14 +1,13 @@
const std = @import("std");
const os = std.os;
const posix = std.posix;
const mem = std.mem;
const heap = std.heap;
const debug = std.debug;
const io = std.io;
const meta = std.meta;

pub const std_options = struct {
    pub const logFn = @import("log.zig").log;
};
pub const logFn = @import("log.zig").log;
pub const std_options = std.Options{ .logFn = logFn };

const logger = std.log.scoped(.wayprompt);

@@ -73,9 +72,9 @@ pub fn main() !u8 {
    }
    defer if (getpin) secret.deinit(alloc);

    var fds: [1]os.pollfd = .{.{
    var fds: [1]posix.pollfd = .{.{
        .fd = try frontend.init(&config),
        .events = os.POLL.IN,
        .events = posix.POLL.IN,
        .revents = undefined,
    }};
    defer frontend.deinit();
@@ -92,9 +91,9 @@ pub fn main() !u8 {
            }
        }

        _ = try os.poll(&fds, -1);
        _ = try posix.poll(&fds, -1);

        if (fds[0].revents & os.POLL.IN != 0) {
        if (fds[0].revents & posix.POLL.IN != 0) {
            const ev = try frontend.handleEvent();
            if (ev != .none) {
                try handleEvent(ev, &ret);
@@ -177,7 +176,7 @@ const FlagIt = struct {
fn parseCmdFlags() !void {
    const alloc = arena.allocator();

    var it = FlagIt.new(&os.argv);
    var it = FlagIt.new(&std.os.argv);
    while (it.next()) |flag| {
        if (mem.eql(u8, flag, "--title")) {
            try dupeArg(alloc, &it, &config.labels.title, "--title");
@@ -222,7 +221,7 @@ fn parseCmdFlags() !void {
                \\alternative versions. wayprompt is developed and maintained by
                \\Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de>.
                \\
            , .{os.argv[0]});
            , .{std.os.argv[0]});
            try out_buffer.flush();
            return error.DumpedUsage;
        } else {
diff --git a/src/wayprompt-pinentry.zig b/src/wayprompt-pinentry.zig
index 2a8c145..305636e 100644
--- a/src/wayprompt-pinentry.zig
+++ b/src/wayprompt-pinentry.zig
@@ -2,6 +2,7 @@ const builtin = @import("builtin");
const std = @import("std");
const ascii = std.ascii;
const mem = std.mem;
const posix = std.posix;
const os = std.os;
const io = std.io;
const fs = std.fs;
@@ -9,8 +10,10 @@ const fmt = std.fmt;
const heap = std.heap;
const debug = std.debug;

pub const std_options = struct {
    pub const logFn = @import("log.zig").log;
const logFn = @import("log.zig").log;

pub const std_options = std.Options{
    .logFn = logFn,
};

const logger = std.log.scoped(.wayprompt);
@@ -66,18 +69,18 @@ pub fn main() !u8 {

    const fds_stdin = 0;
    const fds_frontend = 1;
    var fds: [2]os.pollfd = undefined;
    var fds: [2]posix.pollfd = undefined;

    fds[fds_stdin] = .{
        .fd = stdin.handle,
        .events = os.POLL.IN,
        .events = posix.POLL.IN,
        .revents = undefined,
    };
    var stdin_closed: bool = false;

    fds[fds_frontend] = .{
        .fd = try frontend.init(&config),
        .events = os.POLL.IN,
        .events = posix.POLL.IN,
        .revents = undefined,
    };
    defer frontend.deinit();
@@ -103,10 +106,10 @@ pub fn main() !u8 {
        }

        // We don't poll stdin if it has been closed to avoid pointless spinning.
        _ = try os.poll(if (stdin_closed) fds[1..2] else &fds, -1);
        _ = try posix.poll(if (stdin_closed) fds[1..2] else &fds, -1);

        if (!stdin_closed) {
            if (fds[fds_stdin].revents & os.POLL.IN != 0) {
            if (fds[fds_stdin].revents & posix.POLL.IN != 0) {
                const read = try stdin.read(&in_buffer);
                if (read == 0) break;

@@ -122,14 +125,14 @@ pub fn main() !u8 {
            }

            logger.debug("pipe closed.", .{});
            if (fds[fds_stdin].revents & os.POLL.HUP != 0) {
            if (fds[fds_stdin].revents & posix.POLL.HUP != 0) {
                stdin_closed = true;
            }
        }

        if (stdin_closed and mode == .none) break;

        if (fds[fds_frontend].revents & os.POLL.IN != 0) {
        if (fds[fds_frontend].revents & posix.POLL.IN != 0) {
            if (frontend.handleEvent()) |ev| {
                try handleFrontendEvent(out_buffer.writer(), ev);
            } else |err| {
-- 
2.45.2
Reply to thread Export thread (mbox)