-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathbuild.zig
150 lines (123 loc) · 5.25 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const std = @import("std");
const builtin = @import("builtin");
const mach = @import("mach");
const nfd = @import("src/deps/nfd-zig/build.zig");
const zip = @import("src/deps/zip/build.zig");
const content_dir = "assets/";
const ProcessAssetsStep = @import("src/tools/process_assets.zig");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Create our pixi module, where our Modules declaration lives
const pixi_mod = b.createModule(.{
.root_source_file = b.path("src/pixi.zig"),
.optimize = optimize,
.target = target,
});
const zstbi = b.dependency("zstbi", .{ .target = target, .optimize = optimize });
const zmath = b.dependency("zmath", .{ .target = target, .optimize = optimize });
const zip_pkg = zip.package(b, .{});
// Add mach import to our app.
const mach_dep = b.dependency("mach", .{
.target = target,
.optimize = optimize,
});
const zig_imgui_dep = b.dependency("zig_imgui", .{ .target = target, .optimize = optimize });
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 timerModule = b.addModule("timer", .{ .root_source_file = .{ .cwd_relative = "src/tools/timer.zig" } });
// quantization library
const quantizeLib = b.addStaticLibrary(.{
.name = "quantize",
.root_source_file = .{ .cwd_relative = "src/tools/quantize/quantize.zig" },
.target = target,
.optimize = optimize,
});
addImport(quantizeLib, "timer", timerModule);
const quantizeModule = quantizeLib.root_module;
// zgif library
const zgifLibrary = b.addStaticLibrary(.{
.name = "zgif",
.root_source_file = .{ .cwd_relative = "src/tools/gif.zig" },
.target = target,
.optimize = optimize,
});
addCGif(b, zgifLibrary);
addImport(zgifLibrary, "quantize", quantizeModule);
const zgif_module = zgifLibrary.root_module;
zgif_module.addImport("zstbi", zstbi.module("root"));
// Have Mach create the executable for us
// The mod we pass as .app must contain the Modules definition
// And the Modules must include an App containing the main schedule
const exe = mach.addExecutable(mach_dep.builder, .{
.name = "Pixi",
.app = pixi_mod,
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
if (optimize != .Debug) {
switch (target.result.os.tag) {
.windows => exe.subsystem = .Windows,
else => exe.subsystem = .Posix,
}
}
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the example");
pixi_mod.addImport("mach", mach_dep.module("mach"));
pixi_mod.addImport("zstbi", zstbi.module("root"));
pixi_mod.addImport("zmath", zmath.module("root"));
pixi_mod.addImport("nfd", nfd.getModule(b));
pixi_mod.addImport("zip", zip_pkg.module);
pixi_mod.addImport("zig-imgui", imgui_module);
pixi_mod.addImport("zgif", zgif_module);
const nfd_lib = nfd.makeLib(b, target, optimize);
pixi_mod.addImport("nfd", nfd_lib);
if (target.result.isDarwin()) {
// // MacOS: this must be defined for macOS 13.3 and older.
// // Critically, this MUST NOT be included as a -D__kernel_ptr_semantics flag. If it is,
// // then this macro will not be defined even if `defineCMacro` was also called!
//nfd_lib.addCMacro("__kernel_ptr_semantics", "");
//mach.addPaths(nfd_lib);
if (mach_dep.builder.lazyDependency("xcode_frameworks", .{})) |dep| {
nfd_lib.addSystemIncludePath(dep.path("include"));
}
}
exe.linkLibCpp();
exe.linkLibrary(zig_imgui_dep.artifact("imgui"));
exe.linkLibrary(zstbi.artifact("zstbi"));
zip.link(exe);
const assets = try ProcessAssetsStep.init(b, "assets", "src/generated/");
var process_assets_step = b.step("process-assets", "generates struct for all assets");
process_assets_step.dependOn(&assets.step);
exe.step.dependOn(process_assets_step);
const install_content_step = b.addInstallDirectory(.{
.source_dir = .{ .cwd_relative = thisDir() ++ "/" ++ content_dir },
.install_dir = .{ .custom = "" },
.install_subdir = "bin/" ++ content_dir,
});
exe.step.dependOn(&install_content_step.step);
const installArtifact = b.addInstallArtifact(exe, .{});
run_cmd.step.dependOn(&installArtifact.step);
run_step.dependOn(&run_cmd.step);
b.getInstallStep().dependOn(&installArtifact.step);
}
inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse ".";
}
fn addImport(
compile: *std.Build.Step.Compile,
name: [:0]const u8,
module: *std.Build.Module,
) void {
compile.root_module.addImport(name, module);
}
fn addCGif(b: *std.Build, compile: *std.Build.Step.Compile) void {
compile.addIncludePath(std.Build.path(b, "src/deps/cgif/inc"));
compile.addCSourceFile(.{ .file = std.Build.path(b, "src/deps/cgif/cgif.c") });
compile.addCSourceFile(.{ .file = std.Build.path(b, "src/deps/cgif/cgif_raw.c") });
}