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 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); zig_squashfs_options.addOption(bool, "allow_lzo", allow_lzo orelse false); const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const mod = b.addModule("zig_squashfs", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, .link_libc = use_c_libs_option, .valgrind = valgrind, }); mod.addOptions("config", zig_squashfs_options); if (use_c_libs_option == true) { mod.linkSystemLibrary("zlib", .{}); mod.linkSystemLibrary("lzma", .{}); if (allow_lzo == true) mod.linkSystemLibrary("minilzo", .{}); mod.linkSystemLibrary("lz4", .{}); mod.linkSystemLibrary("zstd", .{}); } var version = version_string_option orelse "0.0.0-testing"; if (version[0] == 'v') version = version[1..]; const unsquashfs_options = b.addOptions(); unsquashfs_options.addOption( std.SemanticVersion, "version", try std.SemanticVersion.parse(version), ); var exe_mod = b.createModule(.{ .root_source_file = b.path("src/bin/unsquashfs.zig"), .target = target, .optimize = optimize, .link_libc = use_c_libs_option, .imports = &.{ .{ .name = "zig_squashfs", .module = mod }, }, .valgrind = valgrind, }); exe_mod.addOptions("config", unsquashfs_options); const exe = b.addExecutable(.{ .name = "unsquashfs", .root_module = exe_mod, .use_llvm = true, }); const lib = b.addLibrary(.{ .name = "squashfs", .root_module = mod, }); b.installArtifact(lib); b.installArtifact(exe); const mod_tests = b.addTest(.{ .root_module = mod, }); const run_mod_tests = b.addRunArtifact(mod_tests); const exe_tests = b.addTest(.{ .root_module = exe.root_module, }); const run_exe_tests = b.addRunArtifact(exe_tests); const test_step = b.step("test", "Run tests"); test_step.dependOn(&run_mod_tests.step); test_step.dependOn(&run_exe_tests.step); // zls build check steps const lib_check = b.addLibrary(.{ .name = "squashfs", .root_module = mod, }); const exe_check = b.addExecutable(.{ .name = "unsquashfs", .root_module = exe_mod, }); const check = b.step("check", "Check if unsquashfs compiles"); check.dependOn(&lib_check.step); check.dependOn(&exe_check.step); }