-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.zig
125 lines (99 loc) · 4.27 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
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/demo-application.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);
}
}