-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.zig
152 lines (121 loc) · 4.58 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
const std = @import("std");
const AndroidSdk = @import("vendor/ZigAndroidTemplate/Sdk.zig");
fn initApp(app: *std.build.LibExeObjStep) void {
const cflags = [_][]const u8{
"-std=c99",
"-fno-sanitize=undefined",
};
app.addCSourceFile("src/rendering/stb_truetype.c", &cflags);
app.addIncludeDir("vendor/stb");
}
pub fn build(b: *std.build.Builder) !void {
const mode = b.standardReleaseOptions();
const root_src = "examples/demo-application.zig";
const zigimg = std.build.Pkg{
.name = "zigimg",
.path = .{ .path = "vendor/zigimg/zigimg.zig" },
};
var zero_graphics = std.build.Pkg{
.name = "zero-graphics",
.path = .{ .path = "src/zero-graphics.zig" },
.dependencies = &[_]std.build.Pkg{
zigimg,
},
};
if (b.option(bool, "enable-android", "Enables building the Android application") orelse false) {
// TODO: Move this into a file!
const key_store = AndroidSdk.KeyStore{
.file = "zig-cache/key.store",
.password = "123456",
.alias = "development_key",
};
const sdk = AndroidSdk.init(b, null, .{});
const make_keystore = sdk.initKeystore(key_store, .{});
b.step("init-keystore", "Initializes a fresh debug keystore.").dependOn(make_keystore);
const app_config = AndroidSdk.AppConfig{
.app_name = "zerog-demo",
.display_name = "ZeroGraphics Demo",
.package_name = "net.random_projects.zero_graphics_demo",
.resources = &[_]AndroidSdk.Resource{
.{ .path = "mipmap/icon.png", .content = std.build.FileSource.relative("design/app-icon.png") },
},
.fullscreen = true,
};
const apk_file = "zig-out/demo.apk";
const app = sdk.createApp(
apk_file,
root_src,
app_config,
mode,
.{
.aarch64 = true,
.x86_64 = true,
// 32 bit targets are currently broken
.arm = false, // see https://github.com/ziglang/zig/issues/8885
.x86 = false, // see https://github.com/ziglang/zig/issues/7935
},
key_store,
);
zero_graphics.dependencies = &[_]std.build.Pkg{
zigimg, app.getAndroidPackage("android"),
};
for (app.libraries) |lib| {
lib.addBuildOption([]const u8, "render_backend", "android");
lib.addPackage(zero_graphics);
initApp(lib);
}
b.getInstallStep().dependOn(app.final_step);
const push = app.install();
const run = app.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);
}
// Build desktop application
{
const app = b.addExecutable("zerog-demo", root_src);
app.addPackage(zero_graphics);
app.addBuildOption([]const u8, "render_backend", "desktop_sdl2");
app.setBuildMode(mode);
initApp(app);
const target = b.standardTargetOptions(.{});
app.setTarget(target);
app.linkLibC();
app.linkSystemLibrary("sdl2");
app.install();
const run_cmd = app.run();
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Runs the desktop application");
run_step.dependOn(&run_cmd.step);
}
// Build wasm application
{
const app = b.addSharedLibrary("zerog-demo", root_src, .unversioned);
app.addPackage(zero_graphics);
app.addBuildOption([]const u8, "render_backend", "wasm");
app.setBuildMode(mode);
initApp(app);
// No libc on wasm!
app.setTarget(std.zig.CrossTarget{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
.abi = .musl,
});
app.override_dest_dir = .{ .custom = "../www" };
app.single_threaded = true;
app.install();
const server = b.addExecutable("http-server", "tools/http-server.zig");
server.addPackage(std.build.Pkg{
.name = "apple_pie",
.path = .{ .path = "vendor/apple_pie/src/apple_pie.zig" },
});
const serve = server.run();
serve.step.dependOn(&app.step);
const run_step = b.step("run-wasm", "Serves the wasm app");
run_step.dependOn(&serve.step);
}
}