From 3bfe3367d86d626c5337397465c64f04f0418c4b Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sat, 23 Mar 2024 15:12:47 +0800 Subject: [PATCH] adopt zig master --- .github/workflows/CI.yml | 2 +- .github/workflows/binary.yml | 2 +- .github/workflows/simargs.yml | 2 +- examples/simargs-demo.zig | 4 ++-- src/bin/loc.zig | 20 ++++++++++++++------ src/bin/pidof.zig | 8 ++++---- src/bin/tree.zig | 4 ++-- src/mod/simargs.zig | 6 +++--- 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index abbf022..f19dff9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -25,7 +25,7 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] zig-version: [master] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - uses: goto-bus-stop/setup-zig@v2 diff --git a/.github/workflows/binary.yml b/.github/workflows/binary.yml index 2899779..8b6a607 100644 --- a/.github/workflows/binary.yml +++ b/.github/workflows/binary.yml @@ -30,7 +30,7 @@ jobs: - "arm-linux" - "aarch64-linux" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - uses: goto-bus-stop/setup-zig@v2 diff --git a/.github/workflows/simargs.yml b/.github/workflows/simargs.yml index bfa41cf..fb1d767 100644 --- a/.github/workflows/simargs.yml +++ b/.github/workflows/simargs.yml @@ -22,7 +22,7 @@ jobs: matrix: os: [ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: goto-bus-stop/setup-zig@v2 with: version: master diff --git a/examples/simargs-demo.zig b/examples/simargs-demo.zig index 51c58f3..f38d107 100644 --- a/examples/simargs-demo.zig +++ b/examples/simargs-demo.zig @@ -1,8 +1,8 @@ const std = @import("std"); const simargs = @import("simargs"); -pub const std_options = struct { - pub const log_level: std.log.Level = .info; +pub const std_options = .{ + .log_level = .info, }; pub fn main() !void { diff --git a/src/bin/loc.zig b/src/bin/loc.zig index 2406d44..22b03f1 100644 --- a/src/bin/loc.zig +++ b/src/bin/loc.zig @@ -6,6 +6,10 @@ const util = @import("util.zig"); const StringUtil = util.StringUtil; const fs = std.fs; +pub const std_options = .{ + .log_level = .info, +}; + const IGNORE_DIRS = [_][]const u8{ ".git", "zig-cache", "zig-out", "target", "vendor", "node_modules", "out" }; const Language = enum { @@ -172,10 +176,6 @@ const LinesOfCode = struct { const LocMap = std.enums.EnumMap(Language, LinesOfCode); -pub const std_options = struct { - pub const log_level: std.log.Level = .info; -}; - pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); @@ -350,8 +350,16 @@ fn populateLoc(allocator: std.mem.Allocator, loc_map: *LocMap, dir: fs.Dir, base } }, else => { - var ptr = try std.os.mmap(null, file_size, std.os.PROT.READ, std.os.MAP.PRIVATE, file.handle, 0); - defer std.os.munmap(ptr); + var ptr = try std.posix.mmap( + null, + file_size, + std.posix.PROT.READ, + .{ .TYPE = .PRIVATE }, + + file.handle, + 0, + ); + defer std.posix.munmap(ptr); var offset_so_far: usize = 0; while (offset_so_far < ptr.len) { diff --git a/src/bin/pidof.zig b/src/bin/pidof.zig index c8f99e8..0bd047b 100644 --- a/src/bin/pidof.zig +++ b/src/bin/pidof.zig @@ -42,7 +42,7 @@ pub fn findPids(allocator: std.mem.Allocator, opt: Options, program: []const u8) var procSize: usize = 0; var rc = c.sysctl(&mib, mib.len, null, &procSize, null, 0); if (rc != 0) { - std.debug.print("get proc size, err:{any}", .{std.c.getErrno(rc)}); + std.debug.print("get proc size, err:{any}", .{std.posix.errno(rc)}); return error.sysctl; } @@ -50,7 +50,7 @@ pub fn findPids(allocator: std.mem.Allocator, opt: Options, program: []const u8) // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sysctl.3.html rc = c.sysctl(&mib, mib.len, @ptrCast(procList), &procSize, null, 0); if (rc != 0) { - std.debug.print("get proc list failed, err:{any}", .{std.c.getErrno(rc)}); + std.debug.print("get proc list failed, err:{any}", .{std.posix.errno(rc)}); return error.sysctl; } @@ -91,14 +91,14 @@ pub fn main() !void { if (opt.positional_args.items.len == 0) { std.debug.print("program is not given", .{}); - std.os.exit(1); + std.posix.exit(1); } const program = opt.positional_args.items[0]; const pids = try findPids(allocator, opt.args, program); if (pids.items.len == 0) { - std.os.exit(1); + std.posix.exit(1); } var stdout = std.io.getStdOut().writer(); diff --git a/src/bin/tree.zig b/src/bin/tree.zig index 195b472..7a09746 100644 --- a/src/bin/tree.zig +++ b/src/bin/tree.zig @@ -15,8 +15,8 @@ const mem = std.mem; const testing = std.testing; const fmt = std.fmt; -pub const std_options = struct { - pub const log_level: std.log.Level = .info; +pub const std_options = .{ + .log_level = .info, }; const Mode = enum { diff --git a/src/mod/simargs.zig b/src/mod/simargs.zig index 5b56c30..d93e3a0 100644 --- a/src/mod/simargs.zig +++ b/src/mod/simargs.zig @@ -612,7 +612,7 @@ test "parse/valid option values" { \\ \\ OPTIONS: \\ -h, --help print this help message(required) - \\ -r, --rate FLOAT (default: 2.0e+00) + \\ -r, --rate FLOAT (default: 2e0) \\ --timeout INTEGER (required) \\ --user-agent STRING (default: Brave) \\ @@ -773,8 +773,8 @@ test "parse/default value" { \\ --a2 STRING (default: A2) \\ --b1 INTEGER (default: 1) \\ --b2 INTEGER (default: 11) - \\ --c1 FLOAT (default: 1.5e+00) - \\ --c2 FLOAT (default: 2.5e+00) + \\ --c1 FLOAT (default: 1.5e0) + \\ --c2 FLOAT (default: 2.5e0) \\ --d1 (default: true) \\ --d2 padding message \\