From ab074c9ef8ab9cb81ade41ca1f04589fb39b71ec Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Thu, 2 Apr 2026 14:51:11 -0500 Subject: [PATCH] fix linux build: replace @cImport in broadcaster, bump deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- build.zig.zon | 8 ++++---- src/broadcaster.zig | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 2010d28..41042f8 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,12 +13,12 @@ .hash = "websocket-0.1.0-ZPISdSmqAwCbwcFtrAQC_q9cegdw-iHyrjCftgfMz-Nf", }, .pg = .{ - .url = "git+https://github.com/zzstoatzz/pg.zig?ref=dev#fdc519c42d6df787c4ac5ad9f391baf961d07f9c", - .hash = "pg-0.0.0-Wp_7gaOBBgAdAUwxkZb82X57EovpFUGWp9IdOSCcgKiL", + .url = "git+https://github.com/zzstoatzz/pg.zig?ref=dev#9ef9a0f407c67ad32958eec3370aa561d53c192b", + .hash = "pg-0.0.0-Wp_7ga-BBgBHHXZdYhK8gv2IJXXqUKeIdkTuluGSnipW", }, .rocksdb = .{ - .url = "https://github.com/zzstoatzz/rocksdb-zig/archive/9be930b.tar.gz", - .hash = "rocksdb-9.7.4-z_CUTr_HAADkz2Rte8o6L0TSrQnXjZZuw2kzve5n88RQ", + .url = "https://github.com/zzstoatzz/rocksdb-zig/archive/cdef67bb2141df4eb4906d367d60285d1527ab3f.tar.gz", + .hash = "rocksdb-9.7.4-z_CUTsLJAAArLT8DEcD1Li7XthpIinhXrcitqQLFIKLK", }, }, .paths = .{ diff --git a/src/broadcaster.zig b/src/broadcaster.zig index 1a8397f..96583f2 100644 --- a/src/broadcaster.zig +++ b/src/broadcaster.zig @@ -961,7 +961,7 @@ fn appendProcMetrics(w: *Io.Writer, io: Io) void { // glibc malloc stats — mallinfo fields are c_int, bitcast to u32 to extend range to 4 GiB. // note: mallinfo only reports the main arena, not per-thread arenas. // for accurate total heap picture, rely on RssAnon from /proc/self/status above. - const mi = malloc_h.mallinfo(); + const mi = mallinfo(); const arena: u64 = @as(u32, @bitCast(mi.arena)); const in_use: u64 = @as(u32, @bitCast(mi.uordblks)); const free_bytes: u64 = @as(u32, @bitCast(mi.fordblks)); @@ -982,8 +982,38 @@ fn appendProcMetrics(w: *Io.Writer, io: Io) void { , .{ arena, in_use, free_bytes, mmap_bytes }) catch {}; } -const posix_vfs = @cImport(@cInclude("sys/statvfs.h")); -const malloc_h = @cImport(@cInclude("malloc.h")); +// glibc mallinfo struct — fields are c_int (32-bit), we bitcast to u32 for range. +const MallInfo = extern struct { + arena: c_int, + ordblks: c_int, + smblks: c_int, + hblks: c_int, + hblkhd: c_int, + usmblks: c_int, + fsmblks: c_int, + uordblks: c_int, + fordblks: c_int, + keepcost: c_int, +}; + +const mallinfo = @extern(*const fn () callconv(.c) MallInfo, .{ .name = "mallinfo" }); + +// statvfs — only the fields we use (f_frsize, f_blocks, f_bavail) +const StatVfs = extern struct { + f_bsize: c_ulong, + f_frsize: c_ulong, + f_blocks: c_ulong, + f_bfree: c_ulong, + f_bavail: c_ulong, + f_files: c_ulong, + f_ffree: c_ulong, + f_favail: c_ulong, + f_fsid: c_ulong, + f_flag: c_ulong, + f_namemax: c_ulong, +}; + +const statvfs_fn = @extern(*const fn ([*:0]const u8, *StatVfs) callconv(.c) c_int, .{ .name = "statvfs" }); fn appendDiskMetrics(w: *Io.Writer, data_dir: []const u8) void { // statvfs needs a null-terminated path @@ -992,8 +1022,8 @@ fn appendDiskMetrics(w: *Io.Writer, data_dir: []const u8) void { @memcpy(path_buf[0..data_dir.len], data_dir); path_buf[data_dir.len] = 0; - var stat: posix_vfs.struct_statvfs = undefined; - if (posix_vfs.statvfs(@ptrCast(&path_buf), &stat) != 0) return; + var stat: StatVfs = undefined; + if (statvfs_fn(@ptrCast(&path_buf), &stat) != 0) return; const block_size: u64 = stat.f_frsize; const total = stat.f_blocks * block_size; -- 2.51.2