Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
321 lines (298 loc) · 14 KB
/
Copy pathbuild.zig
File metadata and controls
321 lines (298 loc) · 14 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
316
317
318
319
320
321
const std = @import("std");
const version = std.SemanticVersion.parse(@import("build.zig.zon").version) catch unreachable;
pub fn build(b: *std.Build) void {
const upstream = b.dependency("libxkbcommon", .{});
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode") orelse .static;
const strip = b.option(bool, "strip", "Omit debug information");
const pic = b.option(bool, "pie", "Produce Position Independent Code");
if (version.major != 1) {
// The versioning used for the shared libraries assumes that the major
// version of xkbcommon as a whole will increase to 2 if and only if there
// is an ABI break, at which point we should probably bump the SONAME of
// all libraries to .so.2.
@compileError("We probably need to bump the SONAME of libxkbcommon");
}
// To avoid an unnecessary SONAME bump, xkbcommon 1.x.y produces
// libxkbcommon.so.0.x.y, libxkbcommon-x11.so.0.x.y, libxkbregistry.so.0.x.y.
const soname_version: std.SemanticVersion = .{
.major = 0,
.minor = version.minor,
.patch = version.patch,
.pre = version.pre,
.build = version.build,
};
// Most of these config options have not been tested.
const xkb_legacy_root = b.option([]const u8, "xkb-legacy-root", " [default=$prefix/share/X11/locale]") orelse b.pathJoin(&.{ b.install_prefix, "share/X11/xkb" });
const xkb_config_root = b.option([]const u8, "xkb-config-root", "The XKB config root [default=$prefix/share/X11/locale]") orelse xkb_legacy_root;
const xkb_config_extra_path = b.option([]const u8, "xkb-config-extra-path", "Extra lookup path for system-wide XKB data [default=$sysconfdir/xkb]") orelse "/etc/xkb";
const x_locale_root = b.option([]const u8, "x-locale-root", "The X locale root [default=$prefix/share/X11/locale]") orelse b.pathJoin(&.{ b.install_prefix, "share/X11/locale" });
// const bash_completion_path = b.option([]const u8, "bash-completion-path", "Directory for bash completion scripts");
const default_rules = b.option([]const u8, "default-rules", "Default XKB ruleset") orelse "evdev";
const default_model = b.option([]const u8, "default-model", "Default XKB model") orelse "pc105";
const default_layout = b.option([]const u8, "default-layout", "Default XKB layout") orelse "us";
const default_variant = b.option([]const u8, "default-variant", "Default XKB variant");
const default_options = b.option([]const u8, "default-options", "Default XKB options");
// const enable_tools = b.option(bool, "enable-tools", "Enable building tools") orelse true;
const enable_x11 = b.option(bool, "enable-x11", "Enable building the xkbcommon-x11 library") orelse true;
// const enable_docs = b.option(bool, "enable-docs", "Enable building the documentation") orelse false;
// const enable_cool_uris = b.option(bool, "enable-cool-uris", "Enable creating redirections to maintain stable documentation pages") orelse false;
// const enable_wayland = b.option(bool, "enable-wayland", "nable support for Wayland utility programs (requires enable-tools)") orelse true;
const enable_xkbregistry = b.option(bool, "enable-xkbregistry", "Enable building libxkbregistry") orelse true;
// const enable_bash_completion = b.option(bool, "enable-bash-completion", "Enable installing bash completion scripts") orelse true;
const config_header = b.addConfigHeader(.{}, .{
.EXIT_INVALID_USAGE = 2,
.LIBXKBCOMMON_VERSION = b.fmt("{f}", .{version}),
.LIBXKBCOMMON_TOOL_PATH = b.pathJoin(&.{ b.install_prefix, "libexec/xkbcommon" }),
._GNU_SOURCE = 1,
.DFLT_XKB_LEGACY_ROOT = xkb_legacy_root,
.DFLT_XKB_CONFIG_ROOT = xkb_config_root,
.DFLT_XKB_CONFIG_EXTRA_PATH = xkb_config_extra_path,
.XLOCALEDIR = x_locale_root,
.DEFAULT_XKB_RULES = default_rules,
.DEFAULT_XKB_MODEL = default_model,
.DEFAULT_XKB_LAYOUT = default_layout,
.DEFAULT_XKB_VARIANT = .null,
.DEFAULT_XKB_OPTIONS = .null,
.HAVE_UNISTD_H = 1,
.HAVE_DIRENT_H = 1,
.HAVE_XKB_EXTENSIONS_DIRECTORIES = 1,
.HAVE___BUILTIN_EXPECT = 1,
.HAVE_REAL_PATH = 1,
.HAVE_EACCESS = if (target.result.os.tag == .linux) @as(i64, 1) else null,
.HAVE_EUIDACCESS = if (target.result.os.tag == .linux) @as(i64, 1) else null,
.HAVE_MMAP = if (target.result.os.tag != .windows) @as(i64, 1) else null,
.HAVE_MKOSTEMP = if (target.result.os.tag != .windows) @as(i64, 1) else null,
.HAVE_POSIX_FALLOCATE = if (target.result.os.tag != .windows) @as(i64, 1) else null,
.HAVE_STRNDUP = if (target.result.os.tag != .windows) @as(i64, 1) else null,
.HAVE_ASPRINTF = 1,
.HAVE_VASPRINTF = null,
.HAVE_OPEN_MEMSTREAM = if (target.result.os.tag != .windows) @as(i64, 1) else null,
.HAVE_SECURE_GETENV = if (target.result.os.tag != .windows) @as(i64, 1) else null,
.PATH_MAX = @as(i64, if (target.result.os.tag == .windows) 260 else 4096),
});
if (default_variant) |variant| {
config_header.addValues(.{ .DEFAULT_XKB_VARIANT = variant });
} else {
config_header.addValues(.{ .DEFAULT_XKB_VARIANT = .NULL });
}
if (default_options) |options| {
config_header.addValues(.{ .DEFAULT_XKB_OPTIONS = options });
} else {
config_header.addValues(.{ .DEFAULT_XKB_OPTIONS = .NULL });
}
const generated_parser = generateParser(b, upstream);
const update_parser = b.step("update-parser", "Updated parser.c and parser.h (requires bison)");
if (generated_parser) |generated| {
const generated_parser_c, const generated_parser_h = generated;
const update = b.addUpdateSourceFiles();
update_parser.dependOn(&update.step);
update.addCopyFileToSource(generated_parser_c, "parser.c");
update.addCopyFileToSource(generated_parser_h, "parser.h");
} else {
update_parser.addError("unable to find bison in $PATH or search prefixes (--search-prefix)", .{}) catch {};
update_parser.addError("parser.c and parser.h could not be updated", .{}) catch {};
}
const use_system_bison = b.systemIntegrationOption("bison", .{});
const parser_c: std.Build.LazyPath, const parser_h: std.Build.LazyPath = if (use_system_bison)
generated_parser orelse {
std.log.err("Could not find a compatible YACC program (bison or byacc)", .{});
return;
}
else
.{ b.path("parser.c"), b.path("parser.h") };
const xkbcommon = b.addLibrary(.{
.linkage = linkage,
.name = "xkbcommon",
.version = soname_version,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
.pic = pic,
.sanitize_c = if (@hasDecl(std.zig, "SanitizeC")) .off else false,
}),
});
xkbcommon.root_module.addCSourceFiles(.{
.files = libxkbcommon_sources,
.root = upstream.path(""),
.flags = cflags,
});
xkbcommon.root_module.addConfigHeader(config_header);
xkbcommon.root_module.addCSourceFile(.{ .file = parser_c });
xkbcommon.root_module.addIncludePath(parser_h.dirname());
xkbcommon.installHeader(upstream.path("include/xkbcommon/xkbcommon.h"), "xkbcommon/xkbcommon.h");
xkbcommon.installHeader(upstream.path("include/xkbcommon/xkbcommon-compat.h"), "xkbcommon/xkbcommon-compat.h");
xkbcommon.installHeader(upstream.path("include/xkbcommon/xkbcommon-compose.h"), "xkbcommon/xkbcommon-compose.h");
xkbcommon.installHeader(upstream.path("include/xkbcommon/xkbcommon-keysyms.h"), "xkbcommon/xkbcommon-keysyms.h");
xkbcommon.installHeader(upstream.path("include/xkbcommon/xkbcommon-names.h"), "xkbcommon/xkbcommon-names.h");
xkbcommon.root_module.addIncludePath(upstream.path("."));
xkbcommon.root_module.addIncludePath(upstream.path("src"));
xkbcommon.root_module.addIncludePath(upstream.path("include"));
xkbcommon.version_script = upstream.path("xkbcommon.map");
b.installArtifact(xkbcommon);
if (enable_x11) {
const libxkbcommon_x11 = b.addLibrary(.{
.linkage = linkage,
.name = "xkbcommon-x11",
.version = soname_version,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
.pic = pic,
}),
});
libxkbcommon_x11.root_module.linkSystemLibrary("xcb", .{}); // TODO
libxkbcommon_x11.root_module.linkSystemLibrary("xcb-xkb", .{}); // TODO
libxkbcommon_x11.root_module.addCSourceFiles(.{
.files = libxkbcommon_x11_sources,
.root = upstream.path(""),
.flags = cflags,
});
libxkbcommon_x11.root_module.addConfigHeader(config_header);
libxkbcommon_x11.installHeader(upstream.path("include/xkbcommon/xkbcommon-x11.h"), "xkbcommon/xkbcommon-x11.h");
libxkbcommon_x11.root_module.addIncludePath(upstream.path("src"));
libxkbcommon_x11.root_module.addIncludePath(upstream.path("include"));
libxkbcommon_x11.version_script = upstream.path("xkbcommon-x11.map");
b.installArtifact(libxkbcommon_x11);
}
if (enable_xkbregistry) {
const libxkbregistry = b.addLibrary(.{
.linkage = linkage,
.name = "xkbregistry",
.version = soname_version,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
.pic = pic,
}),
});
libxkbregistry.root_module.addCSourceFiles(.{
.files = libxkbregistry_sources,
.root = upstream.path(""),
.flags = cflags,
});
libxkbregistry.root_module.addConfigHeader(config_header);
libxkbregistry.installHeader(upstream.path("include/xkbcommon/xkbregistry.h"), "xkbcommon/xkbregistry.h");
libxkbregistry.root_module.addIncludePath(upstream.path("src"));
libxkbregistry.root_module.addIncludePath(upstream.path("include"));
libxkbregistry.version_script = upstream.path("xkbregistry.map");
b.installArtifact(libxkbregistry);
const link_system_libxml = b.systemIntegrationOption("libxml2", .{});
if (link_system_libxml) {
libxkbregistry.root_module.linkSystemLibrary("libxml-2.0", .{});
libxkbregistry.root_module.addCMacro("HAVE_XML_CTXT_SET_ERRORHANDLER", "0"); // TODO Since libxml-2.13
libxkbregistry.root_module.addCMacro("HAVE_XML_CTXT_PARSE_DTD", "0"); // TODO Since libxml-2.14
} else if (b.lazyDependency("libxml2", .{
.target = target,
.optimize = optimize,
.minimum = true,
.valid = true,
.sax1 = true,
})) |libxml2| {
libxkbregistry.root_module.linkLibrary(libxml2.artifact("xml"));
libxkbregistry.root_module.addCMacro("HAVE_XML_CTXT_SET_ERRORHANDLER", "1");
libxkbregistry.root_module.addCMacro("HAVE_XML_CTXT_PARSE_DTD", "1");
}
}
}
fn generateParser(
b: *std.Build,
upstream: *std.Build.Dependency,
) ?struct { std.Build.LazyPath, std.Build.LazyPath } {
const parser_write_files = b.addWriteFiles();
_ = parser_write_files.addCopyFile(upstream.path("src/xkbcomp/parser.y"), "parser.y");
const run_step = std.Build.Step.Run.create(b, "run bison");
run_step.setCwd(parser_write_files.getDirectory());
run_step.addFileArg(.{ .cwd_relative = b.findProgram(&.{ "bison", "win_bison" }, &.{}) catch return null });
run_step.addArg("--defines=parser.h");
run_step.addArg("-o");
const parser_c = run_step.addOutputFileArg("parser.c");
run_step.addArgs(&.{ "-p", "_xkbcommon_", "--no-lines" });
run_step.addFileArg(upstream.path("src/xkbcomp/parser.y"));
const write_header = b.addWriteFiles();
write_header.step.dependOn(&run_step.step);
const parser_h = write_header.addCopyFile(
.{ .generated = .{ .file = &parser_write_files.generated_directory, .sub_path = "parser.h" } },
"parser.h",
);
return .{ parser_c, parser_h };
}
const cflags: []const []const u8 = &.{
"-std=c11",
"-fno-strict-aliasing",
"-Wno-unused-parameter",
"-Wno-missing-field-initializers",
"-Wpointer-arith",
"-Wmissing-declarations",
"-Wformat=2",
"-Wstrict-prototypes",
"-Wmissing-prototypes",
"-Wnested-externs",
"-Wbad-function-cast",
"-Wshadow",
"-Wlogical-op",
"-Wdate-time",
"-Wwrite-strings",
"-Wno-documentation-deprecated-sync",
"-Wno-pedantic",
};
const libxkbcommon_sources: []const []const u8 = &.{
"src/compose/parser.c",
"src/compose/paths.c",
"src/compose/state.c",
"src/compose/table.c",
"src/xkbcomp/action.c",
"src/xkbcomp/ast-build.c",
"src/xkbcomp/compat.c",
"src/xkbcomp/expr.c",
"src/xkbcomp/include.c",
"src/xkbcomp/keycodes.c",
"src/xkbcomp/keymap.c",
"src/xkbcomp/keymap-dump.c",
"src/xkbcomp/keywords.c",
"src/xkbcomp/rules.c",
"src/xkbcomp/scanner.c",
"src/xkbcomp/symbols.c",
"src/xkbcomp/types.c",
"src/xkbcomp/vmod.c",
"src/xkbcomp/xkbcomp.c",
"src/atom.c",
"src/context.c",
"src/context-priv.c",
"src/keysym.c",
"src/keysym-case-mappings.c",
"src/keysym-utf.c",
"src/keymap.c",
"src/keymap-compare.c",
"src/keymap-priv.c",
"src/rmlvo.c",
"src/scanner-utils.c",
"src/state.c",
"src/text.c",
"src/utf8.c",
"src/utf8-decoding.c",
"src/utils.c",
"src/utils-paths.c",
};
const libxkbcommon_x11_sources: []const []const u8 = &.{
"src/x11/keymap.c",
"src/x11/state.c",
"src/x11/util.c",
"src/context.c",
"src/context-priv.c",
"src/keymap-priv.c",
"src/atom.c",
"src/utils.c",
};
const libxkbregistry_sources: []const []const u8 = &.{
"src/registry.c",
"src/utils.c",
"src/util-list.c",
};