-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.zig
290 lines (276 loc) · 9.01 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
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
const std = @import("std");
const ArrayListUnmanaged = std.ArrayListUnmanaged;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const xml = b.dependency("xml", .{}).module("xml");
const exe = b.addExecutable(.{
.name = "translate-gir",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.linkLibC();
exe.root_module.addImport("xml", xml);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the binding generator");
run_step.dependOn(&run_cmd.step);
// Tests
const test_step = b.step("test", "Run all tests");
const exe_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_tests.linkLibC();
exe_tests.root_module.addImport("xml", xml);
const test_exe_step = b.step("test-exe", "Run tests for the binding generator");
test_exe_step.dependOn(&b.addRunArtifact(exe_tests).step);
test_step.dependOn(test_exe_step);
const GirProfile = enum { gnome46, gnome47 };
const gir_profile = b.option(GirProfile, "gir-profile", "Predefined GIR profile for codegen");
const codegen_modules: []const []const u8 = b.option([]const []const u8, "modules", "Modules to codegen") orelse if (gir_profile) |profile| switch (profile) {
.gnome46 => &.{
"Adw-1",
"AppStream-1.0",
"AppStreamCompose-1.0",
"AppStreamGlib-1.0",
"Atk-1.0",
"Atspi-2.0",
"cairo-1.0",
"CudaGst-1.0",
"DBus-1.0",
"Dex-1",
"fontconfig-2.0",
"freetype2-2.0",
"GCab-1.0",
"Gck-1",
"Gck-2",
"Gcr-3",
"Gcr-4",
"GcrUi-3",
"GDesktopEnums-3.0",
"Gdk-3.0",
"Gdk-4.0",
"GdkPixbuf-2.0",
"GdkPixdata-2.0",
"GdkWayland-4.0",
"GdkX11-3.0",
"GdkX11-4.0",
"Gee-0.8",
"Geoclue-2.0",
"Gio-2.0",
"GioUnix-2.0",
"GIRepository-2.0",
"GIRepository-3.0",
"GL-1.0",
"GLib-2.0",
"GLibUnix-2.0",
"GModule-2.0",
"GObject-2.0",
"Graphene-1.0",
"Gsk-4.0",
"Gst-1.0",
"GstAllocators-1.0",
"GstApp-1.0",
"GstAudio-1.0",
"GstBadAudio-1.0",
"GstBase-1.0",
"GstCheck-1.0",
"GstController-1.0",
"GstCuda-1.0",
"GstGL-1.0",
"GstGLEGL-1.0",
"GstGLWayland-1.0",
"GstGLX11-1.0",
"GstInsertBin-1.0",
"GstMpegts-1.0",
"GstNet-1.0",
"GstPbutils-1.0",
"GstPlay-1.0",
"GstPlayer-1.0",
"GstRtp-1.0",
"GstRtsp-1.0",
"GstSdp-1.0",
"GstTag-1.0",
"GstTranscoder-1.0",
"GstVa-1.0",
"GstVideo-1.0",
// "GstVulkan-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
// "GstVulkanWayland-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
// "GstVulkanXCB-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
"GstWebRTC-1.0",
"Gtk-3.0",
"Gtk-4.0",
"GtkSource-5",
"GUdev-1.0",
"Handy-1",
"HarfBuzz-0.0",
"IBus-1.0",
"JavaScriptCore-4.1",
"JavaScriptCore-6.0",
"Json-1.0",
"Libproxy-1.0",
"libxml2-2.0",
"Manette-0.2",
"Nice-0.1",
"Notify-0.7",
"Pango-1.0",
"PangoCairo-1.0",
"PangoFc-1.0",
"PangoFT2-1.0",
"PangoOT-1.0",
"Polkit-1.0",
"Rsvg-2.0",
"Secret-1",
"Soup-3.0",
"Tracker-3.0",
// "Vulkan-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
"WebKit2-4.1",
"WebKit2WebExtension-4.1",
"WebKit-6.0",
"WebKitWebProcessExtension-6.0",
"win32-1.0",
"xfixes-4.0",
"xft-2.0",
"xlib-2.0",
"Xmlb-2.0",
"xrandr-1.3",
},
.gnome47 => &.{
"Adw-1",
"AppStream-1.0",
"AppStreamCompose-1.0",
"Atk-1.0",
"Atspi-2.0",
"cairo-1.0",
"CudaGst-1.0",
"DBus-1.0",
"Dex-1",
"fontconfig-2.0",
"freetype2-2.0",
"GCab-1.0",
"Gck-1",
"Gck-2",
"Gcr-3",
"Gcr-4",
"GcrUi-3",
"GDesktopEnums-3.0",
"Gdk-3.0",
"Gdk-4.0",
"GdkPixbuf-2.0",
"GdkPixdata-2.0",
"GdkWayland-4.0",
"GdkX11-3.0",
"GdkX11-4.0",
"Gee-0.8",
"Geoclue-2.0",
"Gio-2.0",
"GioUnix-2.0",
"GIRepository-2.0",
"GIRepository-3.0",
"GL-1.0",
"GLib-2.0",
"GLibUnix-2.0",
"GModule-2.0",
"GObject-2.0",
"Graphene-1.0",
"Gsk-4.0",
"Gst-1.0",
"GstAllocators-1.0",
"GstAnalytics-1.0",
"GstApp-1.0",
"GstAudio-1.0",
"GstBadAudio-1.0",
"GstBase-1.0",
"GstCheck-1.0",
"GstController-1.0",
"GstCuda-1.0",
// "GstDxva-1.0", // Not usable on Linux
"GstGL-1.0",
"GstGLEGL-1.0",
"GstGLWayland-1.0",
"GstGLX11-1.0",
"GstInsertBin-1.0",
"GstMpegts-1.0",
"GstMse-1.0",
"GstNet-1.0",
"GstPbutils-1.0",
"GstPlay-1.0",
"GstPlayer-1.0",
"GstRtp-1.0",
"GstRtsp-1.0",
"GstSdp-1.0",
"GstTag-1.0",
"GstTranscoder-1.0",
"GstVa-1.0",
"GstVideo-1.0",
// "GstVulkan-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
// "GstVulkanWayland-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
// "GstVulkanXCB-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
"GstWebRTC-1.0",
"Gtk-3.0",
"Gtk-4.0",
"GtkSource-5",
"GUdev-1.0",
"Handy-1",
"HarfBuzz-0.0",
"IBus-1.0",
"JavaScriptCore-4.1",
"JavaScriptCore-6.0",
"Json-1.0",
"Libproxy-1.0",
"libxml2-2.0",
"Manette-0.2",
"Nice-0.1",
"Notify-0.7",
"Pango-1.0",
"PangoCairo-1.0",
"PangoFc-1.0",
"PangoFT2-1.0",
"PangoOT-1.0",
"Polkit-1.0",
"Rsvg-2.0",
"Secret-1",
"Soup-3.0",
"Tracker-3.0",
"Tsparql-3.0",
// "Vulkan-1.0", // https://github.com/ianprime0509/zig-gobject/issues/89
"WebKit2-4.1",
"WebKit2WebExtension-4.1",
"WebKit-6.0",
"WebKitWebProcessExtension-6.0",
"win32-1.0",
"xfixes-4.0",
"xft-2.0",
"xlib-2.0",
"Xmlb-2.0",
"xrandr-1.3",
},
} else &.{};
const gir_files_path = b.option([]const u8, "gir-files-path", "Path to GIR files") orelse "/usr/share/gir-1.0";
const codegen_cmd = b.addRunArtifact(exe);
codegen_cmd.addPrefixedDirectoryArg("--gir-dir=", .{ .cwd_relative = gir_files_path });
codegen_cmd.addPrefixedDirectoryArg("--gir-fixes-dir=", b.path("gir-fixes"));
codegen_cmd.addPrefixedDirectoryArg("--bindings-dir=", b.path("binding-overrides"));
codegen_cmd.addPrefixedDirectoryArg("--extensions-dir=", b.path("extensions"));
const bindings_dir = codegen_cmd.addPrefixedOutputDirectoryArg("--output-dir=", "bindings");
codegen_cmd.addPrefixedDirectoryArg("--abi-test-output-dir=", b.path("test/abi"));
_ = codegen_cmd.addPrefixedDepFileOutputArg("--dependency-file=", "codegen-deps");
codegen_cmd.addArgs(codegen_modules);
// This is needed to tell Zig that the command run can be cached despite
// having output files.
codegen_cmd.expectExitCode(0);
const install_bindings = b.addInstallDirectory(.{
.source_dir = bindings_dir,
.install_dir = .prefix,
.install_subdir = "bindings",
});
const codegen_step = b.step("codegen", "Generate all bindings");
codegen_step.dependOn(&install_bindings.step);
}