-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathbuild.zig
More file actions
178 lines (148 loc) · 6.13 KB
/
build.zig
File metadata and controls
178 lines (148 loc) · 6.13 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
const std = @import("std");
const builtin = @import("builtin");
const zip = @import("src/deps/zip/build.zig");
const dvui = @import("dvui");
const content_dir = "assets/";
const ProcessAssetsStep = @import("src/tools/process_assets.zig");
const update = @import("update.zig");
const GitDependency = update.GitDependency;
fn update_step(step: *std.Build.Step, _: std.Build.Step.MakeOptions) !void {
const deps = &.{
GitDependency{
// mach_objc
.url = "https://github.com/foxnne/mach-objc",
.branch = "set_shadow",
},
GitDependency{
// zigwin32
.url = "https://github.com/marlersoft/zigwin32",
.branch = "main",
},
GitDependency{
// icons
.url = "https://github.com/foxnne/zig-lib-icons",
.branch = "dvui",
},
GitDependency{
// dvui
.url = "https://github.com/foxnne/dvui-dev",
.branch = "defer_render",
},
GitDependency{
// assetpack
.url = "https://github.com/foxnne/assetpack",
.branch = "main",
},
};
try update.update_dependency(step.owner.allocator, deps);
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const no_emit = b.option(bool, "no-emit", "Check for compile errors without emitting any code") orelse false;
const step = b.step("update", "update git dependencies");
step.makeFn = update_step;
const zip_pkg = zip.package(b, .{});
const accesskit = b.option(dvui.AccesskitOptions, "accesskit", "Enable accesskit") orelse .off;
const dvui_dep = b.dependency("dvui", .{ .target = target, .optimize = optimize, .backend = .sdl3, .accesskit = accesskit });
const zstbi_lib = b.addLibrary(.{
.name = "zstbi",
.root_module = b.addModule("zstbi", .{
.target = target,
.optimize = optimize,
.root_source_file = .{ .cwd_relative = "src/deps/stbi/zstbi.zig" },
}),
});
const zstbi_module = zstbi_lib.root_module;
zstbi_lib.addCSourceFile(.{ .file = std.Build.path(b, "src/deps/stbi/zstbi.c") });
const msf_gif_lib = b.addLibrary(.{
.name = "msf_gif",
.root_module = b.addModule("msf_gif", .{
.target = target,
.optimize = optimize,
.root_source_file = .{ .cwd_relative = "src/deps/msf_gif/msf_gif.zig" },
}),
});
const msf_gif_module = msf_gif_lib.root_module;
msf_gif_lib.addCSourceFile(.{ .file = std.Build.path(b, "src/deps/msf_gif/msf_gif.c") });
const exe = b.addExecutable(.{
.name = "Pixi",
.root_module = b.addModule("App", .{
.target = target,
.optimize = optimize,
.root_source_file = .{ .cwd_relative = "src/App.zig" },
}),
});
const assetpack = @import("assetpack");
const assets_module = assetpack.pack(b, b.path("assets"), .{});
exe.root_module.addImport("assets", assets_module);
const known_folders = b.dependency("known_folders", .{
.target = target,
.optimize = optimize,
}).module("known-folders");
exe.root_module.addImport("known-folders", known_folders);
if (no_emit) {
b.getInstallStep().dependOn(&exe.step);
} else {
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");
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 installArtifact = b.addInstallArtifact(exe, .{});
run_cmd.step.dependOn(&installArtifact.step);
run_step.dependOn(&run_cmd.step);
b.getInstallStep().dependOn(&installArtifact.step);
}
exe.root_module.addImport("zstbi", zstbi_module);
exe.root_module.addImport("msf_gif", msf_gif_module);
exe.root_module.addImport("zip", zip_pkg.module);
exe.root_module.addImport("dvui", dvui_dep.module("dvui_sdl3"));
// Add backend module so we can use it directly
exe.root_module.addImport("backend", dvui_dep.module("sdl3"));
if (b.lazyDependency("icons", .{ .target = target, .optimize = optimize })) |dep| {
exe.root_module.addImport("icons", dep.module("icons"));
}
if (target.result.os.tag == .macos) {
if (b.lazyDependency("zig_objc", .{
.target = target,
.optimize = optimize,
})) |dep| {
exe.root_module.addImport("objc", dep.module("objc"));
}
// Custom NSVisualEffectView subclass that forwards right-click to the content view (SDL).
exe.addCSourceFile(.{ .file = std.Build.path(b, "src/objc/PixiVisualEffectView.m") });
// Target for macOS menu bar items (File menu); calls back into Zig via PixiNativeMenuAction.
exe.addCSourceFile(.{ .file = std.Build.path(b, "src/objc/PixiMenuTarget.m") });
} else if (target.result.os.tag == .windows) {
if (b.lazyDependency("zigwin32", .{})) |dep| {
exe.root_module.addImport("win32", dep.module("win32"));
}
exe.linkSystemLibrary("comctl32");
}
exe.linkLibCpp();
zip.link(exe);
}
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") });
}