atproto relay implementation in zig zlay.waow.tech
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix linux build: replace @cImport in broadcaster, bump deps

- broadcaster.zig: replace @cImport for malloc.h and sys/statvfs.h
with @extern declarations (zig 0.16 C translator fails on glibc
stdio2.h __builtin_va_arg_pack)
- bump pg.zig to 9ef9a0f (fix posix.close → std.c.close)
- bump rocksdb-zig to cdef67b (fix std.Thread.RwLock → pthread)

verified: native build, x86_64-linux-gnu cross-compile, tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

zzstoatzz ab074c9e f6edce6e

+39 -9
+4 -4
build.zig.zon
··· 13 13 .hash = "websocket-0.1.0-ZPISdSmqAwCbwcFtrAQC_q9cegdw-iHyrjCftgfMz-Nf", 14 14 }, 15 15 .pg = .{ 16 - .url = "git+https://github.com/zzstoatzz/pg.zig?ref=dev#fdc519c42d6df787c4ac5ad9f391baf961d07f9c", 17 - .hash = "pg-0.0.0-Wp_7gaOBBgAdAUwxkZb82X57EovpFUGWp9IdOSCcgKiL", 16 + .url = "git+https://github.com/zzstoatzz/pg.zig?ref=dev#9ef9a0f407c67ad32958eec3370aa561d53c192b", 17 + .hash = "pg-0.0.0-Wp_7ga-BBgBHHXZdYhK8gv2IJXXqUKeIdkTuluGSnipW", 18 18 }, 19 19 .rocksdb = .{ 20 - .url = "https://github.com/zzstoatzz/rocksdb-zig/archive/9be930b.tar.gz", 21 - .hash = "rocksdb-9.7.4-z_CUTr_HAADkz2Rte8o6L0TSrQnXjZZuw2kzve5n88RQ", 20 + .url = "https://github.com/zzstoatzz/rocksdb-zig/archive/cdef67bb2141df4eb4906d367d60285d1527ab3f.tar.gz", 21 + .hash = "rocksdb-9.7.4-z_CUTsLJAAArLT8DEcD1Li7XthpIinhXrcitqQLFIKLK", 22 22 }, 23 23 }, 24 24 .paths = .{
+35 -5
src/broadcaster.zig
··· 961 961 // glibc malloc stats — mallinfo fields are c_int, bitcast to u32 to extend range to 4 GiB. 962 962 // note: mallinfo only reports the main arena, not per-thread arenas. 963 963 // for accurate total heap picture, rely on RssAnon from /proc/self/status above. 964 - const mi = malloc_h.mallinfo(); 964 + const mi = mallinfo(); 965 965 const arena: u64 = @as(u32, @bitCast(mi.arena)); 966 966 const in_use: u64 = @as(u32, @bitCast(mi.uordblks)); 967 967 const free_bytes: u64 = @as(u32, @bitCast(mi.fordblks)); ··· 982 982 , .{ arena, in_use, free_bytes, mmap_bytes }) catch {}; 983 983 } 984 984 985 - const posix_vfs = @cImport(@cInclude("sys/statvfs.h")); 986 - const malloc_h = @cImport(@cInclude("malloc.h")); 985 + // glibc mallinfo struct — fields are c_int (32-bit), we bitcast to u32 for range. 986 + const MallInfo = extern struct { 987 + arena: c_int, 988 + ordblks: c_int, 989 + smblks: c_int, 990 + hblks: c_int, 991 + hblkhd: c_int, 992 + usmblks: c_int, 993 + fsmblks: c_int, 994 + uordblks: c_int, 995 + fordblks: c_int, 996 + keepcost: c_int, 997 + }; 998 + 999 + const mallinfo = @extern(*const fn () callconv(.c) MallInfo, .{ .name = "mallinfo" }); 1000 + 1001 + // statvfs — only the fields we use (f_frsize, f_blocks, f_bavail) 1002 + const StatVfs = extern struct { 1003 + f_bsize: c_ulong, 1004 + f_frsize: c_ulong, 1005 + f_blocks: c_ulong, 1006 + f_bfree: c_ulong, 1007 + f_bavail: c_ulong, 1008 + f_files: c_ulong, 1009 + f_ffree: c_ulong, 1010 + f_favail: c_ulong, 1011 + f_fsid: c_ulong, 1012 + f_flag: c_ulong, 1013 + f_namemax: c_ulong, 1014 + }; 1015 + 1016 + const statvfs_fn = @extern(*const fn ([*:0]const u8, *StatVfs) callconv(.c) c_int, .{ .name = "statvfs" }); 987 1017 988 1018 fn appendDiskMetrics(w: *Io.Writer, data_dir: []const u8) void { 989 1019 // statvfs needs a null-terminated path ··· 992 1022 @memcpy(path_buf[0..data_dir.len], data_dir); 993 1023 path_buf[data_dir.len] = 0; 994 1024 995 - var stat: posix_vfs.struct_statvfs = undefined; 996 - if (posix_vfs.statvfs(@ptrCast(&path_buf), &stat) != 0) return; 1025 + var stat: StatVfs = undefined; 1026 + if (statvfs_fn(@ptrCast(&path_buf), &stat) != 0) return; 997 1027 998 1028 const block_size: u64 = stat.f_frsize; 999 1029 const total = stat.f_blocks * block_size;