Skip to content

Commit

Permalink
Update build.zig
Browse files Browse the repository at this point in the history
  • Loading branch information
mgord9518 committed Sep 3, 2024
1 parent abdfc1e commit ecf1ab2
Showing 1 changed file with 33 additions and 38 deletions.
71 changes: 33 additions & 38 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 = &.{
Expand Down Expand Up @@ -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 => {},
}

Expand All @@ -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 => {},
}

Expand All @@ -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 => {},
}

Expand All @@ -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 => {},
}

Expand All @@ -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);
Expand All @@ -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");
Expand Down

0 comments on commit ecf1ab2

Please sign in to comment.