From 8b8c9a772f1b95aaca2cab898654f225a782ecf3 Mon Sep 17 00:00:00 2001 From: "Caleb J. Gardner" Date: Mon, 9 Mar 2026 00:16:19 -0500 Subject: [PATCH] Added -Ddebug build option Re-added errors from settings xattr values --- .zed/debug.json | 7 +------ README.md | 6 ++++-- build.zig | 17 +++++++++++------ src/inode.zig | 5 ++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.zed/debug.json b/.zed/debug.json index 198e0f6..1bcdda2 100644 --- a/.zed/debug.json +++ b/.zed/debug.json @@ -11,12 +11,7 @@ "build": { "command": "zig", - "args": [ - "build", - "-Doptimize=Debug", - "-Duse_c_libs=true", - "-Dvalgrind=true", - ], + "args": ["build", "-Duse_c_libs=true", "-Ddebug=true"], }, "program": "zig-out/bin/unsquashfs", diff --git a/README.md b/README.md index 53c64bb..083f316 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ Instead of using Zig's standard library for decompression, use the system's C li Enable compiling with LZO decompression support. The LZO library currently has some issues with Zig when imported so it's easier to just disable it by default. Only has an effect when using `-Duse_c_libs=true`. -> `-Dvalgrind=true` +> `-Ddebug=true` -Just sets the valgrind build option. +Sets various build options that make debugging easier. Specifically, debug optimization is forced, valgrind support is enabled, error tracing is enabled, stipping is disabled, and copmilation uses LLVM (this is due to some linking issues when on Debug optimization and is required for debugging tools such as `lldb`. In the future this may be removed from the debug flag). > `-Dversion=0.0.0` @@ -37,6 +37,8 @@ Most features are present except for the following: This is some basic observation's I've made about this library's performance when compared to `unsquashfs`. Unless otherwise stated, most observations were made when extracting my test archive (which is fairly small and uses zstd compression) and with `--release=fast`. +Currently, my only performance checks are checking execution time, nothing deeper. + * Under ideal circumstances, my library is ~70% slower (.12s vs .20s). * Using Zig decompression libraries *significantly* increases decompression time by ~600%. Under ideal circumstances. * Performance improvements/regressions will be common. I'm still learning Zig. diff --git a/build.zig b/build.zig index 55da7bd..2299ec0 100644 --- a/build.zig +++ b/build.zig @@ -3,7 +3,7 @@ const std = @import("std"); pub fn build(b: *std.Build) !void { const use_c_libs_option = b.option(bool, "use_c_libs", "Use C versions of decompression libraries instead of the Zig standard library ones"); const allow_lzo = b.option(bool, "allow_lzo", "Compile with lzo support"); - const valgrind = b.option(bool, "valgrind", "Compile with valgrind integration"); + const debug = b.option(bool, "debug", "Enable options to make debugging easier."); const version_string_option = b.option([]const u8, "version", "Version of the library/binary"); const zig_squashfs_options = b.addOptions(); @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) !void { const mod = b.addModule("zig_squashfs", .{ .root_source_file = b.path("src/root.zig"), .target = target, - .optimize = optimize, + .optimize = if (debug == true) .Debug else optimize, .link_libc = use_c_libs_option, - .valgrind = valgrind, + .valgrind = debug, + .error_tracing = debug, + .strip = if (debug == true) false else null, }); mod.addOptions("config", zig_squashfs_options); if (use_c_libs_option == true) { @@ -41,23 +43,26 @@ pub fn build(b: *std.Build) !void { var exe_mod = b.createModule(.{ .root_source_file = b.path("src/bin/unsquashfs.zig"), .target = target, - .optimize = optimize, + .optimize = if (debug == true) .Debug else optimize, .link_libc = use_c_libs_option, .imports = &.{ .{ .name = "zig_squashfs", .module = mod }, }, - .valgrind = valgrind, + .valgrind = debug, + .error_tracing = debug, + .strip = if (debug == true) false else null, }); exe_mod.addOptions("config", unsquashfs_options); const exe = b.addExecutable(.{ .name = "unsquashfs", .root_module = exe_mod, - // .use_llvm = true, This can be needed to properly debug + .use_llvm = debug, }); const lib = b.addLibrary(.{ .name = "squashfs", .root_module = mod, + .use_llvm = debug, }); b.installArtifact(lib); diff --git a/src/inode.zig b/src/inode.zig index 48f1f4b..39e7738 100644 --- a/src/inode.zig +++ b/src/inode.zig @@ -171,14 +171,13 @@ pub fn setMetadata(self: Inode, alloc: std.mem.Allocator, tables: *Tables, fil: const xattrs = try tables.xattr_table.get(alloc, idx); defer alloc.free(xattrs); for (xattrs) |kv| { - const res = std.os.linux.fsetxattr(fil.handle, @ptrCast(kv.key), @ptrCast(kv.value), kv.value.len, 0); + const res = std.os.linux.fsetxattr(fil.handle, kv.key, kv.value.ptr, kv.value.len, 0); alloc.free(kv.key); alloc.free(kv.value); if (res != 0) { if (options.verbose) options.verbose_writer.?.print("fsetxattr has result of: {}\n", .{res}) catch {}; - //TODO: Currently this seems a bit flakey, so we just ignore the result... for now. - // return error.SetXattr; + return error.SetXattr; } } }