From ecf1ab29f4a08c642719626c28e9759618924012 Mon Sep 17 00:00:00 2001 From: Mathew Gordon Date: Tue, 3 Sep 2024 01:51:09 -0600 Subject: [PATCH] Update build.zig --- build.zig | 71 ++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/build.zig b/build.zig index d81bbb6..28e3996 100644 --- a/build.zig +++ b/build.zig @@ -38,6 +38,13 @@ pub fn build(b: *std.Build) !void { .strip = strip, }); + const unit_tests = b.addTest(.{ + .root_source_file = b.path("test/test.zig"), + .target = target, + .optimize = optimize, + .strip = strip, + }); + const squashfuse_module = b.addModule("squashfuse", .{ .root_source_file = b.path("lib/root.zig"), .imports = &.{ @@ -87,9 +94,16 @@ pub fn build(b: *std.Build) !void { b.installArtifact(lib); exe.linkLibrary(lib); + unit_tests.linkLibrary(lib); + }, + .libdeflate_dynamic => { + exe.linkSystemLibrary("deflate"); + unit_tests.linkSystemLibrary("deflate"); + }, + .libz_dynamic => { + exe.linkSystemLibrary("z"); + unit_tests.linkSystemLibrary("z"); }, - .libdeflate_dynamic => exe.linkSystemLibrary("deflate"), - .libz_dynamic => exe.linkSystemLibrary("z"), .libdeflate_dynlib, .libz_dynlib, .zig_stdlib => {}, } @@ -104,8 +118,12 @@ pub fn build(b: *std.Build) !void { b.installArtifact(lib); exe.linkLibrary(lib); + unit_tests.linkLibrary(lib); + }, + .liblzma_dynamic => { + exe.linkSystemLibrary("lzma"); + unit_tests.linkSystemLibrary("lzma"); }, - .liblzma_dynamic => exe.linkSystemLibrary("lzma"), .liblzma_dynlib, .zig_stdlib => {}, } @@ -120,8 +138,12 @@ pub fn build(b: *std.Build) !void { b.installArtifact(lib); exe.linkLibrary(lib); + unit_tests.linkLibrary(lib); + }, + .liblz4_dynamic => { + exe.linkSystemLibrary("lz4"); + unit_tests.linkSystemLibrary("lz4"); }, - .liblz4_dynamic => exe.linkSystemLibrary("lz4"), .liblz4_dynlib => {}, } @@ -136,8 +158,12 @@ pub fn build(b: *std.Build) !void { b.installArtifact(lib); exe.linkLibrary(lib); + unit_tests.linkLibrary(lib); + }, + .libzstd_dynamic => { + exe.linkSystemLibrary("zstd"); + unit_tests.linkSystemLibrary("zstd"); }, - .libzstd_dynamic => exe.linkSystemLibrary("zstd"), .libzstd_dynlib, .zig_stdlib => {}, } @@ -146,6 +172,8 @@ pub fn build(b: *std.Build) !void { exe.root_module.addImport("fuse", fuse_module); exe.root_module.addImport("clap", clap_module); + unit_tests.root_module.addImport("squashfuse", squashfuse_module); + b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); @@ -157,39 +185,6 @@ pub fn build(b: *std.Build) !void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - const unit_tests = b.addTest(.{ - .root_source_file = b.path("test/test.zig"), - .target = target, - .optimize = optimize, - .strip = strip, - }); - - unit_tests.root_module.addImport("squashfuse", squashfuse_module); - - unit_tests.linkLibrary(try buildLibdeflate(b, .{ - .name = "deflate", - .target = target, - .optimize = optimize, - })); - - unit_tests.linkLibrary(try buildLiblzma(b, .{ - .name = "lzma", - .target = target, - .optimize = optimize, - })); - - unit_tests.linkLibrary(try buildLiblz4(b, .{ - .name = "lz4", - .target = target, - .optimize = optimize, - })); - - unit_tests.linkLibrary(try buildLibzstd(b, .{ - .name = "zstd", - .target = target, - .optimize = optimize, - })); - const run_unit_tests = b.addRunArtifact(unit_tests); const test_step = b.step("test", "Run unit tests");