-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.zig
93 lines (73 loc) · 3.44 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const std = @import("std");
const builtin = @import("builtin");
const mach = @import("mach");
const content_dir = "assets/";
const src_path = "src/aftersun.zig";
const ProcessAssetsStep = @import("src/tools/process_assets.zig").ProcessAssetsStep;
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const zstbi = b.dependency("zstbi", .{ .target = target, .optimize = optimize });
const zflecs = b.dependency("zflecs", .{ .target = target, .optimize = optimize });
const zmath = b.dependency("zmath", .{ .target = target, .optimize = optimize });
const use_sysgpu = b.option(bool, "use_sysgpu", "Use sysgpu") orelse false;
const mach_dep = b.dependency("mach", .{
.target = target,
.optimize = optimize,
});
const zig_imgui_dep = b.dependency("zig_imgui", .{});
const imgui_module = b.addModule("zig-imgui", .{
.root_source_file = zig_imgui_dep.path("src/imgui.zig"),
.imports = &.{
.{ .name = "mach", .module = mach_dep.module("mach") },
},
});
const build_options = b.addOptions();
build_options.addOption(bool, "use_sysgpu", use_sysgpu);
const app = try mach.CoreApp.init(b, mach_dep.builder, .{
.name = "aftersun",
.src = src_path,
.target = target,
.deps = &.{
.{ .name = "zstbi", .module = zstbi.module("root") },
.{ .name = "zmath", .module = zmath.module("root") },
.{ .name = "zflecs", .module = zflecs.module("root") },
.{ .name = "zig-imgui", .module = imgui_module },
.{ .name = "build-options", .module = build_options.createModule() },
},
.optimize = optimize,
});
const run_step = b.step("run", "Run aftersun");
run_step.dependOn(&app.run.step);
const unit_tests = b.addTest(.{
.root_source_file = b.path(src_path),
.target = target,
.optimize = optimize,
});
unit_tests.root_module.addImport("zstbi", zstbi.module("root"));
unit_tests.root_module.addImport("zmath", zmath.module("root"));
unit_tests.root_module.addImport("zflecs", zflecs.module("root"));
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
app.compile.root_module.addImport("zstbi", zstbi.module("root"));
app.compile.root_module.addImport("zmath", zmath.module("root"));
app.compile.root_module.addImport("zflecs", zflecs.module("root"));
app.compile.root_module.addImport("zig-imgui", imgui_module);
app.compile.linkLibrary(zstbi.artifact("zstbi"));
app.compile.linkLibrary(zflecs.artifact("flecs"));
app.compile.linkLibrary(zig_imgui_dep.artifact("imgui"));
const assets = ProcessAssetsStep.init(b, "assets", "src/assets.zig", "src/animations.zig");
const process_assets_step = b.step("process-assets", "generates struct for all assets");
process_assets_step.dependOn(&assets.step);
app.compile.step.dependOn(&assets.step);
const install_content_step = b.addInstallDirectory(.{
.source_dir = .{ .cwd_relative = thisDir() ++ "/" ++ content_dir },
.install_dir = .{ .custom = "" },
.install_subdir = "bin/" ++ content_dir,
});
app.compile.step.dependOn(&install_content_step.step);
}
inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse ".";
}