Added -Ddebug build option

Re-added errors from settings xattr values
This commit is contained in:
Caleb J. Gardner
2026-03-09 00:16:19 -05:00
parent f563648b20
commit 8b8c9a772f
4 changed files with 18 additions and 17 deletions
+1 -6
View File
@@ -11,12 +11,7 @@
"build": { "build": {
"command": "zig", "command": "zig",
"args": [ "args": ["build", "-Duse_c_libs=true", "-Ddebug=true"],
"build",
"-Doptimize=Debug",
"-Duse_c_libs=true",
"-Dvalgrind=true",
],
}, },
"program": "zig-out/bin/unsquashfs", "program": "zig-out/bin/unsquashfs",
+4 -2
View File
@@ -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`. 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` > `-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`. 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). * Under ideal circumstances, my library is ~70% slower (.12s vs .20s).
* Using Zig decompression libraries *significantly* increases decompression time by ~600%. Under ideal circumstances. * Using Zig decompression libraries *significantly* increases decompression time by ~600%. Under ideal circumstances.
* Performance improvements/regressions will be common. I'm still learning Zig. * Performance improvements/regressions will be common. I'm still learning Zig.
+11 -6
View File
@@ -3,7 +3,7 @@ const std = @import("std");
pub fn build(b: *std.Build) !void { 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 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 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 version_string_option = b.option([]const u8, "version", "Version of the library/binary");
const zig_squashfs_options = b.addOptions(); const zig_squashfs_options = b.addOptions();
@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) !void {
const mod = b.addModule("zig_squashfs", .{ const mod = b.addModule("zig_squashfs", .{
.root_source_file = b.path("src/root.zig"), .root_source_file = b.path("src/root.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = if (debug == true) .Debug else optimize,
.link_libc = use_c_libs_option, .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); mod.addOptions("config", zig_squashfs_options);
if (use_c_libs_option == true) { if (use_c_libs_option == true) {
@@ -41,23 +43,26 @@ pub fn build(b: *std.Build) !void {
var exe_mod = b.createModule(.{ var exe_mod = b.createModule(.{
.root_source_file = b.path("src/bin/unsquashfs.zig"), .root_source_file = b.path("src/bin/unsquashfs.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = if (debug == true) .Debug else optimize,
.link_libc = use_c_libs_option, .link_libc = use_c_libs_option,
.imports = &.{ .imports = &.{
.{ .name = "zig_squashfs", .module = mod }, .{ .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); exe_mod.addOptions("config", unsquashfs_options);
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "unsquashfs", .name = "unsquashfs",
.root_module = exe_mod, .root_module = exe_mod,
// .use_llvm = true, This can be needed to properly debug .use_llvm = debug,
}); });
const lib = b.addLibrary(.{ const lib = b.addLibrary(.{
.name = "squashfs", .name = "squashfs",
.root_module = mod, .root_module = mod,
.use_llvm = debug,
}); });
b.installArtifact(lib); b.installArtifact(lib);
+2 -3
View File
@@ -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); const xattrs = try tables.xattr_table.get(alloc, idx);
defer alloc.free(xattrs); defer alloc.free(xattrs);
for (xattrs) |kv| { 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.key);
alloc.free(kv.value); alloc.free(kv.value);
if (res != 0) { if (res != 0) {
if (options.verbose) if (options.verbose)
options.verbose_writer.?.print("fsetxattr has result of: {}\n", .{res}) catch {}; 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;
} }
} }
} }