diff --git a/build.zig.zon b/build.zig.zon index 07fd011..1f3e940 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,8 +5,9 @@ .minimum_zig_version = "0.15.2", .dependencies = .{ .zlib_ng = .{ - .url = "https://github.com/CalebQ42/zig-zlib-ng/archive/refs/tags/2.3.3.tar.gz", - .hash = "zlib_ng-2.3.3-2HYS4Bw_AADjgv7tkrqjjz2fVz5kRTvha8wN9LEcjYNp", + // .url = "https://github.com/CalebQ42/zig-zlib-ng/archive/refs/tags/2.3.3.tar.gz", + // .hash = "zlib_ng-2.3.3-2HYS4Bw_AADjgv7tkrqjjz2fVz5kRTvha8wN9LEcjYNp", + .path = "../zig-zlib-ng", }, }, .paths = .{ diff --git a/src/archive.zig b/src/archive.zig index f053e0b..a6cc252 100644 --- a/src/archive.zig +++ b/src/archive.zig @@ -18,7 +18,7 @@ const OffsetFile = @import("util/offset_file.zig"); const XattrTable = @import("xattr.zig"); const config = if (builtin.is_test) .{ - .use_c_libs = true, + .use_zig_decomp = builtin.link_libc != true, .allow_lzo = false, } else @import("config"); @@ -45,8 +45,8 @@ pub fn init(alloc: std.mem.Allocator, fil: File, offset: u64) !Archive { .lzma => Decomp.lzmaDecompress, .xz => Decomp.xzDecompress, .zstd => Decomp.zstdDecompress, - .lz4 => if (config.use_c_libs) Decomp.cLz4 else return error.Lz4Unsupported, - .lzo => if (config.use_c_libs and config.allow_lzo) Decomp.lzoDecompress else return error.LzoUnsupported, + .lz4 => if (!config.use_zig_decomp) Decomp.cLz4 else return error.Lz4Unsupported, + .lzo => if (!config.use_zig_decomp and config.allow_lzo) Decomp.lzoDecompress else return error.LzoUnsupported, }; return .{ .alloc = alloc, diff --git a/src/decomp.zig b/src/decomp.zig index 0928e09..de77c23 100644 --- a/src/decomp.zig +++ b/src/decomp.zig @@ -6,7 +6,7 @@ const Reader = std.Io.Reader; const builtin = @import("builtin"); const config = if (builtin.is_test) .{ - .use_c_libs = builtin.link_libc == true, + .use_zig_decomp = builtin.link_libc != true, .allow_lzo = false, // Change once LZO compilation is fixed } else @import("config"); @@ -31,7 +31,7 @@ pub const CompressionType = enum(u16) { pub const DecompFn = *const fn (alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize; // TODO: replace anyerror to definitive error types. -pub const gzipDecompress = if (config.use_c_libs) cGzip else zigGzip; +pub const gzipDecompress = if (!config.use_zig_decomp) cGzip else zigGzip; fn zigGzip(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { var rdr: Reader = .fixed(in); @@ -53,7 +53,7 @@ fn cGzip(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { }; } -pub const lzmaDecompress = if (config.use_c_libs) cLzma else zigLzma; +pub const lzmaDecompress = if (!config.use_zig_decomp) cLzma else zigLzma; fn zigLzma(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { var rdr: Reader = .fixed(in); @@ -90,7 +90,7 @@ fn cLzma(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { }; } -// pub const lzoDecompress = if (config.use_c_libs) cLzo else zigLzo; +// pub const lzoDecompress = if (!config.use_zig_decomp) cLzo else zigLzo; // fn zigLzo(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { // _ = alloc; @@ -123,7 +123,7 @@ pub fn cLzo(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { }; } -pub const xzDecompress = if (config.use_c_libs) cXz else zigXz; +pub const xzDecompress = if (!config.use_zig_decomp) cXz else zigXz; fn zigXz(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { var rdr: Reader = .fixed(in); @@ -161,7 +161,7 @@ fn cXz(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { }; } -// pub const lz4Decompress = if (config.use_c_libs) cLz4 else zigLz4; +// pub const lz4Decompress = if (!config.use_zig_decomp) cLz4 else zigLz4; // fn zigLz4(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { // _ = alloc; @@ -176,7 +176,7 @@ pub fn cLz4(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { return error.Lz4DecompressFailed; } -pub const zstdDecompress = if (config.use_c_libs) cZstd else zigZstd; +pub const zstdDecompress = if (!config.use_zig_decomp) cZstd else zigZstd; pub fn zigZstd(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize { var rdr: Reader = .fixed(in);