-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
73 lines (62 loc) · 2.38 KB
/
build.zig
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
66
67
68
69
70
71
72
73
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// // Setup aseprite module
_ = b.addModule("aseprite", .{
.source_file = .{ .path = "src/aseprite.zig" },
});
// Setup a library for stb_image_write
const stb_image_write = b.addStaticLibrary(.{
.name = "stb_image_write",
.root_source_file = null,
.target = target,
.optimize = optimize,
});
stb_image_write.addCSourceFile(.{ .file = .{ .path = "extern/stb/stb_image_write.c" }, .flags = &.{"-DSTB_IMAGE_WRITE_IMPLEMENTATION"} });
// Setup a library for stb_image_rect_pack
const stb_rect_pack = b.addStaticLibrary(.{
.name = "stb_rect_pack",
.root_source_file = null,
.target = target,
.optimize = optimize,
});
stb_rect_pack.addCSourceFile(.{ .file = .{ .path = "extern/stb/stb_rect_pack.c" }, .flags = &.{"-DSTB_RECT_PACK_IMPLEMENTATION"} });
// Create a step to make the image output directory
const make_image_output_dir = MakeDirStep.create(b, "zig-out/images");
// Setup testing
const module_tests = b.addTest(.{
.root_source_file = .{ .path = "src/tests.zig" },
.target = target,
.optimize = optimize,
});
module_tests.addIncludePath(.{ .path = "extern/stb" });
module_tests.linkLibrary(stb_image_write);
module_tests.linkLibrary(stb_rect_pack);
const run_main_tests = b.addRunArtifact(module_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
test_step.dependOn(&make_image_output_dir.step);
}
/// A step that creates a directory
const MakeDirStep = struct {
step: std.build.Step,
path: []const u8,
pub fn create(owner: *std.Build, path: []const u8) *MakeDirStep {
const self = owner.allocator.create(MakeDirStep) catch @panic("OOM");
self.* = .{
.step = std.Build.Step.init(.{
.id = .custom,
.name = "MakeDir",
.owner = owner,
.makeFn = make,
}),
.path = path,
};
return self;
}
fn make(step: *std.build.Step, _: *std.Progress.Node) !void {
const self = @fieldParentPtr(MakeDirStep, "step", step);
try std.fs.cwd().makePath(self.path);
}
};