-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
65 lines (57 loc) · 2.17 KB
/
build.zig
File metadata and controls
65 lines (57 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const std = @import("std");
pub fn build(b: *std.Build) void {
const testsuite_step = b.step("test:testsuite", "Compile and run testsuite binary");
const test_step = b.step("test", "Run all tests");
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const link_mode = b.option(std.builtin.LinkMode, "linkage", "how the library should be linked (default: static)");
const enable_libpng = b.option(bool, "libpng", "Enable libpng to build the test case.") orelse false;
test_step.dependOn(testsuite_step);
const zlib = b.dependency("zlib", .{
.target = target,
.optimize = optimize,
});
const libspng_src = b.dependency("libspng", .{});
const mod = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
});
mod.linkLibrary(zlib.artifact("z"));
mod.addCSourceFile(.{
.file = libspng_src.path("spng/spng.c"),
});
const lib = b.addLibrary(.{
.name = "spng",
.root_module = mod,
.linkage = link_mode orelse .static,
});
lib.installHeader(libspng_src.path("spng/spng.h"), "spng.h");
b.installArtifact(lib);
// tests
if (enable_libpng) {
if (b.lazyDependency("libpng", .{})) |libpng| {
const testsuite_mod = b.createModule(.{
.target = target,
.optimize = optimize,
});
testsuite_mod.linkLibrary(libpng.artifact("png"));
testsuite_mod.linkLibrary(lib);
testsuite_mod.addCSourceFile(.{
.file = libspng_src.path("tests/testsuite.c"),
});
const testsuite_exe = b.addExecutable(.{
.name = "testsuite",
.root_module = testsuite_mod,
});
const testsuite_exe_run = b.addRunArtifact(testsuite_exe);
if (b.args) |args| {
testsuite_exe_run.addArgs(args);
}
testsuite_step.dependOn(&testsuite_exe_run.step);
}
} else {
const fail_step = b.addFail("pass -Dlibpng to build/run testsuite");
testsuite_step.dependOn(&fail_step.step);
}
}