-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.zig
More file actions
315 lines (296 loc) · 14.4 KB
/
Copy pathbuild.zig
File metadata and controls
315 lines (296 loc) · 14.4 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const module = b.addModule("wio", .{
.root_source_file = b.path("src/wio.zig"),
.target = target,
.optimize = optimize,
});
const enable_drop = b.option(bool, "enable_drop", "Enable drag-and-drop support (default: false)") orelse false;
const enable_framebuffer = b.option(bool, "enable_framebuffer", "Enable software framebuffer support (default: false)") orelse false;
const enable_opengl = b.option(bool, "enable_opengl", "Enable OpenGL support (default: false)") orelse false;
const enable_vulkan = b.option(bool, "enable_vulkan", "Enable Vulkan support (default: false)") orelse false;
const enable_joystick = b.option(bool, "enable_joystick", "Enable joystick support (default: false)") orelse false;
const enable_audio = b.option(bool, "enable_audio", "Enable audio support (default: false)") orelse false;
var enable_x11 = false;
var enable_wayland = false;
const unix_backends = b.option([]const u8, "unix_backends", "List of enabled backends (default: x11,wayland)") orelse "x11,wayland";
var backend_iter = std.mem.tokenizeScalar(u8, unix_backends, ',');
while (backend_iter.next()) |backend| {
if (std.mem.eql(u8, backend, "x11")) {
enable_x11 = true;
} else if (std.mem.eql(u8, backend, "wayland")) {
enable_wayland = true;
} else {
@panic("option 'unix_backends' is invalid");
}
}
const system_integration = b.systemIntegrationOption("wio", .{});
const options = b.addOptions();
options.addOption(bool, "drop", enable_drop);
options.addOption(bool, "framebuffer", enable_framebuffer);
options.addOption(bool, "opengl", enable_opengl);
options.addOption(bool, "vulkan", enable_vulkan);
options.addOption(bool, "joystick", enable_joystick);
options.addOption(bool, "audio", enable_audio);
options.addOption(bool, "x11", enable_x11);
options.addOption(bool, "wayland", enable_wayland);
options.addOption(bool, "system_integration", system_integration);
module.addOptions("build_options", options);
if (enable_drop) module.addCMacro("WIO_DROP", "");
if (enable_framebuffer) module.addCMacro("WIO_FRAMEBUFFER", "");
if (enable_opengl) module.addCMacro("WIO_OPENGL", "");
if (enable_vulkan) module.addCMacro("WIO_VULKAN", "");
if (enable_joystick) module.addCMacro("WIO_JOYSTICK", "");
if (enable_audio) module.addCMacro("WIO_AUDIO", "");
if (b.option(bool, "win32_manifest", "Embed application manifest (default: true)") orelse true) {
module.addWin32ResourceFile(.{ .file = b.path("src/win32.rc") });
}
switch (target.result.os.tag) {
.windows => {
if (b.lazyDependency("win32", .{ .target = target, .optimize = optimize })) |win32| {
module.addImport("win32", win32.module("win32"));
}
module.linkSystemLibrary("user32", .{});
module.linkSystemLibrary("shell32", .{});
if (enable_drop or enable_audio) {
module.linkSystemLibrary("ole32", .{});
}
if (enable_framebuffer or enable_opengl) {
module.linkSystemLibrary("gdi32", .{});
}
if (enable_opengl) {
module.linkSystemLibrary("opengl32", .{});
}
if (enable_joystick) {
module.linkSystemLibrary("hid", .{});
module.linkSystemLibrary(if (target.result.cpu.arch.isX86()) "xinput9_1_0" else "xinput1_4", .{});
}
},
.macos => {
module.addCSourceFile(.{ .file = b.path("src/macos.m"), .flags = &.{ "-fobjc-arc", "-Wno-deprecated-declarations" } });
if (b.lazyDependency("wio_macos_sdk", .{})) |macos_sdk| {
module.addSystemFrameworkPath(macos_sdk.path("System/Library/Frameworks"));
module.addSystemIncludePath(macos_sdk.path("usr/include"));
module.addLibraryPath(macos_sdk.path("usr/lib"));
}
module.linkFramework("Cocoa", .{});
if (enable_vulkan) {
module.linkFramework("QuartzCore", .{});
}
if (enable_joystick) {
module.linkFramework("IOKit", .{});
}
if (enable_audio) {
module.linkFramework("CoreAudio", .{});
module.linkFramework("AudioUnit", .{});
module.linkFramework("AudioToolbox", .{});
}
},
.linux, .openbsd, .netbsd, .freebsd, .dragonfly, .illumos => |tag| {
if (target.result.abi.isAndroid()) {
if (b.lazyDependency("android", .{})) |android| {
module.addImport("android", android.module("android"));
}
const translate_c = b.addTranslateC(.{
.root_source_file = b.addWriteFiles().add("cimport.c",
\\#include <jni.h>
\\#include <android/input.h>
\\#include <android/native_window_jni.h>
\\#include <EGL/egl.h>
\\#include <vulkan/vulkan.h>
\\#include <vulkan/vulkan_android.h>
\\#define _Nullable
\\#include <aaudio/AAudio.h>
\\
),
.target = target,
.optimize = optimize,
});
module.addImport("c", translate_c.createModule());
module.linkSystemLibrary("android", .{});
if (enable_opengl) {
module.linkSystemLibrary("EGL", .{});
}
if (enable_vulkan) {
module.linkSystemLibrary("vulkan", .{});
}
if (enable_audio) {
module.linkSystemLibrary("aaudio", .{});
}
} else {
var cimport: std.ArrayList(u8) = .empty;
if (enable_x11) {
try cimport.appendSlice(b.allocator,
\\#include <X11/Xlib.h>
\\#include <X11/Xatom.h>
\\#include <X11/XKBlib.h>
\\#include <X11/Xcursor/Xcursor.h>
\\#include <GL/glx.h>
\\
);
}
if (enable_wayland) {
if (!system_integration) {
try cimport.appendSlice(b.allocator,
\\#include <wayland-client-core.h>
\\extern uint32_t (*wio_wl_proxy_get_version)(struct wl_proxy *);
\\extern struct wl_proxy *(*wio_wl_proxy_marshal_flags)(struct wl_proxy *, uint32_t, const struct wl_interface *, uint32_t, uint32_t, ...);
\\extern int (*wio_wl_proxy_add_listener)(struct wl_proxy *, void (**)(void), void *);
\\extern void (*wio_wl_proxy_destroy)(struct wl_proxy *);
\\extern void (*wio_wl_proxy_set_user_data)(struct wl_proxy *, void *);
\\extern void *(*wio_wl_proxy_get_user_data)(struct wl_proxy *);
\\#define wl_proxy_get_version wio_wl_proxy_get_version
\\#define wl_proxy_marshal_flags wio_wl_proxy_marshal_flags
\\#define wl_proxy_add_listener wio_wl_proxy_add_listener
\\#define wl_proxy_destroy wio_wl_proxy_destroy
\\#define wl_proxy_set_user_data wio_wl_proxy_set_user_data
\\#define wl_proxy_get_user_data wio_wl_proxy_get_user_data
\\#include <wayland-protocol.c>
\\
);
}
try cimport.appendSlice(b.allocator,
\\#include <viewporter-protocol.c>
\\#include <fractional-scale-v1-protocol.c>
\\#include <text-input-unstable-v3-protocol.c>
\\#include <tablet-v2-protocol.c>
\\#include <cursor-shape-v1-protocol.c>
\\#include <pointer-constraints-unstable-v1-protocol.c>
\\#include <relative-pointer-unstable-v1-protocol.c>
\\#include <pointer-gestures-unstable-v1-protocol.c>
\\#include <xdg-activation-v1-protocol.c>
\\#include <wayland-client-protocol.h>
\\#include <viewporter-client-protocol.h>
\\#include <fractional-scale-v1-client-protocol.h>
\\#include <text-input-unstable-v3-client-protocol.h>
\\#include <cursor-shape-v1-client-protocol.h>
\\#include <pointer-constraints-unstable-v1-client-protocol.h>
\\#include <relative-pointer-unstable-v1-client-protocol.h>
\\#include <pointer-gestures-unstable-v1-client-protocol.h>
\\#include <xdg-activation-v1-client-protocol.h>
\\#include <xkbcommon/xkbcommon.h>
\\#include <xkbcommon/xkbcommon-compose.h>
\\#include <libdecor.h>
\\#include <wayland-egl.h>
\\#include <EGL/egl.h>
\\
);
}
switch (tag) {
.linux => {
if (enable_joystick) {
try cimport.appendSlice(b.allocator,
\\#include <linux/input.h>
\\#include <libudev.h>
\\
);
}
if (enable_audio) {
try cimport.appendSlice(b.allocator, "#include <pulse/pulseaudio.h>\n");
}
},
.openbsd => {
if (enable_audio) {
try cimport.appendSlice(b.allocator, "#include <sndio.h>\n");
}
},
else => {},
}
const translate_c = b.addTranslateC(.{
.root_source_file = b.addWriteFiles().add("cimport.c", cimport.items),
.target = target,
.optimize = optimize,
});
if (b.lazyDependency("wio_unix_headers", .{})) |unix_headers| {
translate_c.addIncludePath(unix_headers.path("include"));
}
module.addImport("c", translate_c.createModule());
if (system_integration) {
if (enable_x11) {
module.linkSystemLibrary("x11", .{});
module.linkSystemLibrary("xcursor", .{});
if (enable_opengl) {
module.linkSystemLibrary("gl", .{});
}
if (enable_vulkan) {
module.linkSystemLibrary("xext", .{});
}
}
if (enable_wayland) {
module.linkSystemLibrary("wayland-client", .{});
module.linkSystemLibrary("xkbcommon", .{});
module.linkSystemLibrary("libdecor-0", .{});
if (enable_opengl) {
module.linkSystemLibrary("wayland-egl", .{});
module.linkSystemLibrary("egl", .{});
}
}
if (enable_vulkan) {
module.linkSystemLibrary("vulkan", .{});
}
switch (tag) {
.linux => {
if (enable_joystick) {
module.linkSystemLibrary("libudev", .{});
}
if (enable_audio) {
module.linkSystemLibrary("libpulse", .{});
}
},
.openbsd => {
if (enable_audio) {
module.linkSystemLibrary("sndio", .{});
}
},
else => {},
}
}
}
},
.haiku => {
const translate_c = b.addTranslateC(.{
.root_source_file = b.addWriteFiles().add("cimport.c",
\\#include <GL/osmesa.h>
\\
),
.target = target,
.optimize = optimize,
});
module.addImport("c", translate_c.createModule());
module.addCSourceFile(.{ .file = b.path("src/haiku.cpp") });
module.link_libcpp = true;
module.linkSystemLibrary("be", .{});
module.linkSystemLibrary("game", .{});
if (enable_opengl) module.linkSystemLibrary("OSmesa", .{});
if (enable_joystick) module.linkSystemLibrary("device", .{});
if (enable_audio) module.linkSystemLibrary("media", .{});
},
else => {
if (target.result.cpu.arch.isWasm()) {
var exports: std.ArrayList([]const u8) = .empty;
try exports.append(b.allocator, "wioLoop");
try exports.append(b.allocator, "wioEvent");
if (enable_joystick) {
try exports.append(b.allocator, "wioJoystick");
}
if (enable_audio) {
try exports.append(b.allocator, "wioAudioCallback");
}
module.export_symbol_names = exports.items;
}
},
}
}
pub fn setupApk(wio: *std.Build.Dependency, apk: anytype) void {
const b = wio.builder;
apk.addJavaSourceFiles(.{
.root = b.path("src/android"),
.files = &.{
"WioActivity.java",
"WioSurfaceView.java",
"WioInputConnection.java",
},
});
}