Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8002e745e0 | |||
| b5742bc282 | |||
| 51305a1a80 | |||
| 1dc85c62fc |
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "extern/zstd"]
|
||||||
|
path = extern/zstd
|
||||||
|
url = https://github.com/facebook/zstd
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const Compile = std.Build.Step.Compile;
|
||||||
|
const ResolvedTarget = std.Build.ResolvedTarget;
|
||||||
|
const OptimizeMode = std.builtin.OptimizeMode;
|
||||||
|
const Module = std.Build.Module;
|
||||||
|
|
||||||
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_zig_decomp = b.option(bool, "use_zig_decomp", "Use Zig standard library for decompression instead of C libraries.") orelse false;
|
||||||
const allow_lzo = b.option(bool, "allow_lzo", "Compile with lzo support");
|
const allow_lzo = b.option(bool, "allow_lzo", "Compile with lzo support") orelse false;
|
||||||
const debug = b.option(bool, "debug", "Enable options to make debugging easier.");
|
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();
|
||||||
zig_squashfs_options.addOption(bool, "use_c_libs", use_c_libs_option orelse false);
|
zig_squashfs_options.addOption(bool, "use_zig_decomp", use_zig_decomp);
|
||||||
zig_squashfs_options.addOption(bool, "allow_lzo", allow_lzo orelse false);
|
zig_squashfs_options.addOption(bool, "allow_lzo", allow_lzo);
|
||||||
|
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
@@ -16,19 +20,25 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.root_source_file = b.path("src/root.zig"),
|
.root_source_file = b.path("src/root.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = if (debug == true) .Debug else optimize,
|
.optimize = if (debug == true) .Debug else optimize,
|
||||||
.link_libc = use_c_libs_option,
|
.link_libc = !use_zig_decomp,
|
||||||
.valgrind = debug,
|
.valgrind = debug,
|
||||||
.error_tracing = debug,
|
.error_tracing = debug,
|
||||||
.strip = if (debug == true) false else null,
|
.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) {
|
|
||||||
mod.linkSystemLibrary("zlib-ng", .{ .preferred_link_mode = .static });
|
if (!use_zig_decomp) {
|
||||||
|
var zlib = b.dependency("zlib_ng", .{});
|
||||||
|
mod.linkLibrary(zlib.artifact("zng"));
|
||||||
|
|
||||||
mod.linkSystemLibrary("lzma", .{ .preferred_link_mode = .static });
|
mod.linkSystemLibrary("lzma", .{ .preferred_link_mode = .static });
|
||||||
if (allow_lzo == true)
|
if (allow_lzo == true)
|
||||||
mod.linkSystemLibrary("minilzo", .{ .preferred_link_mode = .static });
|
mod.linkSystemLibrary("minilzo", .{ .preferred_link_mode = .static });
|
||||||
mod.linkSystemLibrary("lz4", .{ .preferred_link_mode = .static });
|
mod.linkSystemLibrary("lz4", .{ .preferred_link_mode = .static });
|
||||||
mod.linkSystemLibrary("zstd", .{ .preferred_link_mode = .static });
|
|
||||||
|
const zstd_lib = buildZstdLibrary(b, target, optimize, debug);
|
||||||
|
mod.linkLibrary(zstd_lib);
|
||||||
|
mod.addIncludePath(b.path("extern/zstd/lib/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var version = version_string_option orelse "0.0.0-testing";
|
var version = version_string_option orelse "0.0.0-testing";
|
||||||
@@ -44,7 +54,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.root_source_file = b.path("src/bin/unsquashfs.zig"),
|
.root_source_file = b.path("src/bin/unsquashfs.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = if (debug == true) .Debug else optimize,
|
.optimize = if (debug == true) .Debug else optimize,
|
||||||
.link_libc = use_c_libs_option,
|
.link_libc = !use_zig_decomp,
|
||||||
.imports = &.{
|
.imports = &.{
|
||||||
.{ .name = "zig_squashfs", .module = mod },
|
.{ .name = "zig_squashfs", .module = mod },
|
||||||
},
|
},
|
||||||
@@ -93,3 +103,61 @@ pub fn build(b: *std.Build) !void {
|
|||||||
check.dependOn(&lib_check.step);
|
check.dependOn(&lib_check.step);
|
||||||
check.dependOn(&exe_check.step);
|
check.dependOn(&exe_check.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn buildZstdLibrary(b: *std.Build, target: ResolvedTarget, optimize: OptimizeMode, debug: ?bool) *Compile {
|
||||||
|
var zstd_lib = b.addLibrary(.{
|
||||||
|
.name = "zstd",
|
||||||
|
.linkage = .static,
|
||||||
|
.root_module = b.createModule(.{
|
||||||
|
.target = target,
|
||||||
|
.optimize = if (debug == true) .Debug else optimize,
|
||||||
|
.link_libc = true,
|
||||||
|
}),
|
||||||
|
.use_llvm = debug,
|
||||||
|
});
|
||||||
|
zstd_lib.root_module.addCSourceFiles(.{
|
||||||
|
.root = b.path("extern/zstd/lib/"),
|
||||||
|
.files = &.{
|
||||||
|
"common/debug.c",
|
||||||
|
"common/entropy_common.c",
|
||||||
|
"common/error_private.c",
|
||||||
|
"common/fse_decompress.c",
|
||||||
|
"common/pool.c",
|
||||||
|
"common/threading.c",
|
||||||
|
"common/xxhash.c",
|
||||||
|
"common/zstd_common.c",
|
||||||
|
"compress/fse_compress.c",
|
||||||
|
"compress/hist.c",
|
||||||
|
"compress/huf_compress.c",
|
||||||
|
"compress/zstd_compress.c",
|
||||||
|
"compress/zstd_compress_literals.c",
|
||||||
|
"compress/zstd_compress_sequences.c",
|
||||||
|
"compress/zstd_compress_superblock.c",
|
||||||
|
"compress/zstd_double_fast.c",
|
||||||
|
"compress/zstd_fast.c",
|
||||||
|
"compress/zstd_lazy.c",
|
||||||
|
"compress/zstd_ldm.c",
|
||||||
|
"compress/zstdmt_compress.c",
|
||||||
|
"compress/zstd_opt.c",
|
||||||
|
"compress/zstd_preSplit.c",
|
||||||
|
"decompress/huf_decompress.c",
|
||||||
|
"decompress/zstd_ddict.c",
|
||||||
|
"decompress/zstd_decompress_block.c",
|
||||||
|
"decompress/zstd_decompress.c",
|
||||||
|
"dictBuilder/cover.c",
|
||||||
|
"dictBuilder/divsufsort.c",
|
||||||
|
"dictBuilder/fastcover.c",
|
||||||
|
"dictBuilder/zdict.c",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
zstd_lib.root_module.addCSourceFiles(.{
|
||||||
|
.root = b.path("extern/zstd/lib/decompress"),
|
||||||
|
.files = &.{"huf_decompress_amd64.S"},
|
||||||
|
});
|
||||||
|
zstd_lib.installHeadersDirectory(b.path("extern/zstd/lib/"), &.{}, .{});
|
||||||
|
zstd_lib.installHeadersDirectory(b.path("extern/zstd/lib/common/"), &.{}, .{});
|
||||||
|
zstd_lib.installHeadersDirectory(b.path("extern/zstd/lib/compress/"), &.{}, .{});
|
||||||
|
zstd_lib.installHeadersDirectory(b.path("extern/zstd/lib/dictBuilder/"), &.{}, .{});
|
||||||
|
zstd_lib.installHeadersDirectory(b.path("extern/zstd/lib/"), &.{}, .{});
|
||||||
|
return zstd_lib;
|
||||||
|
}
|
||||||
|
|||||||
+7
-1
@@ -3,7 +3,13 @@
|
|||||||
.version = "0.0.6",
|
.version = "0.0.6",
|
||||||
.fingerprint = 0x37ba29474b87f145, // Changing this has security and trust implications.
|
.fingerprint = 0x37ba29474b87f145, // Changing this has security and trust implications.
|
||||||
.minimum_zig_version = "0.15.2",
|
.minimum_zig_version = "0.15.2",
|
||||||
.dependencies = .{},
|
.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",
|
||||||
|
.path = "../zig-zlib-ng",
|
||||||
|
},
|
||||||
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
"build.zig.zon",
|
"build.zig.zon",
|
||||||
|
|||||||
+1
Submodule extern/zstd added at f8745da6ff
+3
-3
@@ -18,7 +18,7 @@ const OffsetFile = @import("util/offset_file.zig");
|
|||||||
const XattrTable = @import("xattr.zig");
|
const XattrTable = @import("xattr.zig");
|
||||||
|
|
||||||
const config = if (builtin.is_test) .{
|
const config = if (builtin.is_test) .{
|
||||||
.use_c_libs = true,
|
.use_zig_decomp = builtin.link_libc != true,
|
||||||
.allow_lzo = false,
|
.allow_lzo = false,
|
||||||
} else @import("config");
|
} else @import("config");
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@ pub fn init(alloc: std.mem.Allocator, fil: File, offset: u64) !Archive {
|
|||||||
.lzma => Decomp.lzmaDecompress,
|
.lzma => Decomp.lzmaDecompress,
|
||||||
.xz => Decomp.xzDecompress,
|
.xz => Decomp.xzDecompress,
|
||||||
.zstd => Decomp.zstdDecompress,
|
.zstd => Decomp.zstdDecompress,
|
||||||
.lz4 => if (config.use_c_libs) Decomp.cLz4 else return error.Lz4Unsupported,
|
.lz4 => if (!config.use_zig_decomp) Decomp.cLz4 else return error.Lz4Unsupported,
|
||||||
.lzo => if (config.use_c_libs and config.allow_lzo) Decomp.lzoDecompress else return error.LzoUnsupported,
|
.lzo => if (!config.use_zig_decomp and config.allow_lzo) Decomp.lzoDecompress else return error.LzoUnsupported,
|
||||||
};
|
};
|
||||||
return .{
|
return .{
|
||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
|
|||||||
+8
-8
@@ -6,7 +6,7 @@ const Reader = std.Io.Reader;
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
const config = if (builtin.is_test) .{
|
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
|
.allow_lzo = false, // Change once LZO compilation is fixed
|
||||||
} else @import("config");
|
} 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 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 {
|
fn zigGzip(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
||||||
var rdr: Reader = .fixed(in);
|
var rdr: Reader = .fixed(in);
|
||||||
@@ -43,7 +43,7 @@ fn zigGzip(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
|||||||
fn cGzip(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
fn cGzip(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
||||||
_ = alloc;
|
_ = alloc;
|
||||||
var out_len: usize = out.len;
|
var out_len: usize = out.len;
|
||||||
const res = c.zng_uncompress2(out.ptr, &out_len, in.ptr, in.len);
|
const res = c.zng_uncompress(out.ptr, &out_len, in.ptr, in.len);
|
||||||
return switch (res) {
|
return switch (res) {
|
||||||
c.Z_OK => out_len,
|
c.Z_OK => out_len,
|
||||||
c.Z_MEM_ERROR => error.NotEnoughMemory,
|
c.Z_MEM_ERROR => error.NotEnoughMemory,
|
||||||
@@ -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 {
|
fn zigLzma(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
||||||
var rdr: Reader = .fixed(in);
|
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 {
|
// fn zigLzo(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
||||||
// _ = alloc;
|
// _ = 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 {
|
fn zigXz(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
||||||
var rdr: Reader = .fixed(in);
|
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 {
|
// fn zigLz4(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
||||||
// _ = alloc;
|
// _ = alloc;
|
||||||
@@ -176,7 +176,7 @@ pub fn cLz4(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
|||||||
return error.Lz4DecompressFailed;
|
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 {
|
pub fn zigZstd(alloc: std.mem.Allocator, in: []u8, out: []u8) anyerror!usize {
|
||||||
var rdr: Reader = .fixed(in);
|
var rdr: Reader = .fixed(in);
|
||||||
|
|||||||
Reference in New Issue
Block a user