You can now set when building to use c or zig libraries.

This commit is contained in:
Caleb J. Gardner
2026-02-07 10:58:32 -06:00
parent b64a3ec44a
commit 067eaa87c2
4 changed files with 164 additions and 25 deletions
+29 -14
View File
@@ -1,29 +1,44 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const static = b.option(bool, "static_build", "Build static");
pub fn build(b: *std.Build) !void {
const static_option = b.option(bool, "static_build", "Build static");
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 version_string_option = b.option([]const u8, "version", "Version of the library/binary");
const zig_squashfs_options = b.addOptions();
zig_squashfs_options.addOption(bool, "use_c_libs", use_c_libs_option orelse false);
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
const linkage: std.builtin.LinkMode = .static; // TODO: Add argument to set link mode.
const use_c_libs: bool = false;
_ = use_c_libs;
const mod = b.addModule("zig_squashfs", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = if (use_c_libs_option == true) true else false,
});
mod.addOptions("config", zig_squashfs_options);
if (use_c_libs_option == true)
mod.linkSystemLibrary("zstd", .{});
const unsquashfs_options = b.addOptions();
unsquashfs_options.addOption(std.SemanticVersion, "version_string", try std.SemanticVersion.parse(version_string_option orelse "0.0.0-testing"));
var exe_mod = b.createModule(.{
.root_source_file = b.path("src/bin/unsquashfs.zig"),
.target = target,
.optimize = optimize,
.link_libc = if (use_c_libs_option == true) true else false,
.imports = &.{
.{ .name = "zig_squashfs", .module = mod },
},
});
exe_mod.addOptions("config", unsquashfs_options);
const exe = b.addExecutable(.{
.name = "unsquashfs",
.linkage = linkage,
.root_module = b.createModule(.{
.root_source_file = b.path("src/bin/unsquashfs.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zig_squashfs", .module = mod },
},
}),
.linkage = if (static_option == true) .static else .dynamic,
.root_module = exe_mod,
});
b.installArtifact(exe);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);