-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.zig
177 lines (147 loc) · 6.29 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
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
const std = @import("std");
const Sdk = @import("Sdk.zig");
const Assimp = @import("vendor/zig-assimp/Sdk.zig");
pub fn build(b: *std.build.Builder) !void {
const enable_android = b.option(bool, "enable-android", "Enables android build support. Requires the android sdk and ndk to be installed.") orelse false;
const app_only_step = b.step("app", "Builds only the desktop application");
const sdk = Sdk.init(b, enable_android);
const assimp = Assimp.init(b);
const mode = b.standardReleaseOptions();
const platform = sdk.standardPlatformOptions();
{
const zero_init = b.addExecutable("zero-init", "tools/zero-init/main.zig");
zero_init.addPackage(std.build.Pkg{
.name = "args",
.source = .{ .path = "vendor/args/args.zig" },
});
zero_init.install();
}
// compile the zero-init example so can be sure that it actually compiles!
{
const app = sdk.createApplication("zero_init_app", "tools/zero-init/template/src/main.zig");
app.setDisplayName("ZeroGraphics Init App");
app.setPackageName("net.random_projects.zero_graphics.init_app");
app.setBuildMode(mode);
b.getInstallStep().dependOn(app.compileFor(platform).getStep());
b.getInstallStep().dependOn(app.compileFor(.web).getStep());
if (enable_android) {
b.getInstallStep().dependOn(app.compileFor(.android).getStep());
}
}
{
const converter_api = b.addTranslateC(.{ .path = "tools/zero-convert/api.h" });
const converter = b.addExecutable("zero-convert", "tools/zero-convert/main.zig");
converter.addCSourceFile("tools/zero-convert/converter.cpp", &[_][]const u8{
"-std=c++17",
"-Wall",
"-Wextra",
});
converter.addPackage(std.build.Pkg{
.name = "api",
.source = .{ .generated = &converter_api.output_file },
});
converter.addPackage(std.build.Pkg{
.name = "z3d",
.source = .{ .path = "src/rendering/z3d-format.zig" },
});
converter.addPackage(std.build.Pkg{
.name = "args",
.source = .{ .path = "vendor/args/args.zig" },
});
converter.linkLibC();
converter.linkLibCpp();
assimp.addTo(converter, .static, Assimp.FormatSet.default);
converter.install();
}
const app = sdk.createApplication("demo_application", "examples/features/feature-demo.zig");
app.setDisplayName("ZeroGraphics Demo");
app.setPackageName("net.random_projects.zero_graphics.demo");
app.setBuildMode(mode);
app.addPackage(std.build.Pkg{
.name = "zlm",
.source = .{ .path = "vendor/zlm/zlm.zig" },
});
{
const desktop_exe = app.compileFor(platform);
desktop_exe.install();
app_only_step.dependOn(&desktop_exe.data.desktop.install_step.?.step);
const run_cmd = desktop_exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
// Build wasm application
// TODO: Reinclude when https://github.com/llvm/llvm-project/issues/58557 is fixed.
{
const wasm_build = app.compileFor(.web);
wasm_build.install();
const serve = wasm_build.run();
const build_step = b.step("build-wasm", "Builds the wasm app and installs it.");
build_step.dependOn(wasm_build.install_step.?);
const run_step = b.step("run-wasm", "Serves the wasm app");
run_step.dependOn(&serve.step);
}
if (enable_android) {
const android_build = app.compileFor(.android);
android_build.install();
b.step("init-keystore", "Initializes a fresh debug keystore.").dependOn(sdk.initializeKeystore());
const push = android_build.data.android.install();
const run = android_build.data.android.run();
run.dependOn(push);
const push_step = b.step("install-app", "Push the app to the default ADB target");
push_step.dependOn(push);
const run_step = b.step("run-app", "Runs the Android app on the default ADB target");
run_step.dependOn(run);
}
{
const zero_g_pkg = sdk.getLibraryPackage("zero-graphics");
const zero_ui_pkg = std.build.Pkg{
.name = "zero-ui",
.source = .{ .path = "src/ui/core/ui.zig" },
.dependencies = &.{
zero_g_pkg,
.{
.name = "controls",
.source = .{ .path = "src/ui/standard-controls/standard-controls.zig" },
.dependencies = &.{
.{
.name = "ui",
.source = .{ .path = "src/ui/core/ui.zig" },
},
.{
.name = "TextEditor",
.source = .{ .path = "vendor/text-editor/src/TextEditor.zig" },
.dependencies = &.{
.{
.name = "ziglyph",
.source = .{ .path = "vendor/ziglyph/src/ziglyph.zig" },
},
},
},
},
},
},
};
const ui_demo = sdk.createApplication("ui_demo", "examples/ui/demo.zig");
ui_demo.setDisplayName("Zero UI");
ui_demo.setPackageName("net.random_projects.zero_graphics.ui_demo");
ui_demo.setBuildMode(mode);
ui_demo.addPackage(zero_ui_pkg);
ui_demo.addPackage(.{
.name = "layout-engine",
.source = .{ .path = "src/ui/standard-layout/standard-layout.zig" },
.dependencies = &.{zero_ui_pkg},
});
ui_demo.addPackage(.{
.name = "render-engine",
.source = .{ .path = "src/ui/standard-renderer/standard-renderer.zig" },
.dependencies = &.{ zero_ui_pkg, zero_g_pkg },
});
ui_demo.setInitialResolution(.{ .windowed = .{ .width = 480, .height = 320 } });
const ui_demo_exe = ui_demo.compileFor(platform);
ui_demo_exe.install();
}
}