-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
272 lines (254 loc) · 7.67 KB
/
build.zig
File metadata and controls
272 lines (254 loc) · 7.67 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
const std = @import("std");
const builtin = @import("builtin");
pub const Version = struct {
pub const major = "2";
pub const minor = "12";
pub const micro = "6";
pub fn number() i32 {
// the version number: 1.2.3 value is 10203
return 20126;
}
pub fn dottedString() []const u8 {
return comptime major ++ "." ++ minor ++ "." ++ micro;
}
pub fn extra() []const u8 {
return comptime "-GITv" ++ major ++ "." ++ minor ++ "." ++ micro;
}
};
const Program = struct {
name: []const u8,
path: []const u8,
desc: []const u8,
wrapper: bool = false,
};
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const upstream = b.dependency("libxml2", .{});
const lib = b.addStaticLibrary(.{
.name = "libxml2",
.target = target,
.optimize = optimize,
.link_libc = true,
});
lib.linkSystemLibrary("ws2_32");
const libxml2_config_h = b.addConfigHeader(.{
.style = .{ .cmake = upstream.path("config.h.cmake.in") },
}, .{
.ATTRIBUTE_DESTRUCTOR = "__attribute__((destructor))",
.HAVE_ARPA_INET_H = false,
.HAVE_ATTRIBUTE_DESTRUCTOR = true,
.HAVE_DLFCN_H = false,
.HAVE_DLOPEN = false,
.HAVE_DL_H = false,
.HAVE_FCNTL_H = true,
.HAVE_FTIME = true,
.HAVE_GETTIMEOFDAY = true,
.HAVE_INTTYPES_H = true,
.HAVE_ISASCII = true,
.HAVE_LIBHISTORY = false,
.HAVE_LIBREADLINE = false,
.HAVE_MMAP = false,
.HAVE_MUNMAP = false,
.HAVE_NETDB_H = false,
.HAVE_NETINET_IN_H = false,
.HAVE_POLL_H = false,
.HAVE_PTHREAD_H = false,
.HAVE_SHLLOAD = false,
.HAVE_STAT = true,
.HAVE_STDINT_H = true,
.HAVE_SYS_MMAN_H = false,
.HAVE_SYS_SELECT_H = false,
.HAVE_SYS_SOCKET_H = false,
.HAVE_SYS_STAT_H = true,
.HAVE_SYS_TIMEB_H = true,
.HAVE_SYS_TIME_H = true,
.HAVE_UNISTD_H = true,
.HAVE_VA_COPY = true,
.HAVE_ZLIB_H = false,
.HAVE___VA_COPY = true,
.SUPPORT_IP6 = false,
.VA_LIST_IS_ARRAY = true,
.VERSION = Version.number(),
.XML_SOCKLEN_T = "int",
.XML_THREAD_LOCAL = null,
._UINT32_T = null,
.uint32_t = null,
});
lib.addConfigHeader(libxml2_config_h);
const libxml2_xmlversion_h = b.addConfigHeader(.{
.style = .{ .cmake = upstream.path("include/libxml/xmlversion.h.in") },
.include_path = "libxml/xmlversion.h",
}, .{
.VERSION = Version.dottedString(),
.LIBXML_VERSION_NUMBER = Version.number(),
.LIBXML_VERSION_EXTRA = Version.extra(),
.WITH_TRIO = false,
.WITH_THREADS = true,
.WITH_THREAD_ALLOC = false,
.WITH_TREE = true,
.WITH_OUTPUT = true,
.WITH_PUSH = true,
.WITH_READER = true,
.WITH_PATTERN = true,
.WITH_WRITER = true,
.WITH_SAX1 = true,
.WITH_FTP = false,
.WITH_HTTP = false,
.WITH_VALID = true,
.WITH_HTML = true,
.WITH_LEGACY = false,
.WITH_C14N = true,
.WITH_CATALOG = true,
.WITH_XPATH = true,
.WITH_XPTR = true,
.WITH_XPTR_LOCS = false,
.WITH_XINCLUDE = true,
.WITH_ICONV = false,
.WITH_ICU = false,
.WITH_ISO8859X = true,
.WITH_DEBUG = true,
.WITH_MEM_DEBUG = false,
.WITH_REGEXPS = true,
.WITH_SCHEMAS = true,
.WITH_SCHEMATRON = true,
.WITH_MODULES = true,
.MODULE_EXTENSION = target.result.dynamicLibSuffix(),
.WITH_ZLIB = false,
.WITH_LZMA = false,
});
lib.addConfigHeader(libxml2_xmlversion_h);
lib.installConfigHeader(libxml2_xmlversion_h);
const flags = &.{
"-pedantic",
"-Wall",
"-Wextra",
"-Wshadow",
"-Wpointer-arith",
"-Wcast-align",
"-Wwrite-strings",
"-Wstrict-prototypes",
"-Wmissing-prototypes",
"-Wno-long-long",
"-Wno-format-extra-args",
};
const srcs = &.{
"buf.c",
"c14n.c",
"catalog.c",
"chvalid.c",
"debugXML.c",
"dict.c",
"encoding.c",
"entities.c",
"error.c",
"globals.c",
"hash.c",
"HTMLparser.c",
"HTMLtree.c",
"legacy.c",
"list.c",
// "nanoftp.c", // FTP
"nanohttp.c",
"parser.c",
"parserInternals.c",
"pattern.c",
"relaxng.c",
"SAX.c",
"SAX2.c",
"schematron.c",
"threads.c",
"tree.c",
"uri.c",
"valid.c",
"xinclude.c",
"xlink.c",
"xmlIO.c",
"xmlmemory.c",
"xmlmodule.c",
"xmlreader.c",
"xmlregexp.c",
"xmlsave.c",
"xmlschemas.c",
"xmlschemastypes.c",
"xmlstring.c",
"xmlunicode.c",
"xmlwriter.c",
"xpath.c",
"xpointer.c",
// "xzlib.c", // Zlib
};
lib.addCSourceFiles(.{ .root = upstream.path("."), .files = srcs, .flags = flags });
lib.addIncludePath(upstream.path("include"));
lib.installHeadersDirectory(upstream.path("include/libxml"), "libxml", .{
.include_extensions = &.{".h"},
});
b.installArtifact(lib);
// examples
const examples_step = b.step("examples", "Builds all the examples");
const examples = [_]Program{
.{
.name = "xpath1",
.path = "examples/xpath1.zig",
.desc = "Evaluate XPath expression and prints result node set",
},
.{
.name = "parse1",
.path = "examples/parse1.zig",
.desc = "Parse an XML file to a tree and free it",
},
.{
.name = "parse2",
.path = "examples/parse2.zig",
.desc = "Parse and validate an XML file to a tree and free the result",
},
.{
.name = "parse3",
.path = "examples/parse3.zig",
.desc = "Parse an XML document in memory to a tree and free it",
},
.{
.name = "parse4",
.path = "examples/parse4.zig",
.desc = "Parse an XML document chunk by chunk to a tree and free it",
},
.{
.name = "reader1",
.path = "examples/reader1.zig",
.desc = "Parse an XML file with an xmlReader",
},
.{
.name = "reader2",
.path = "examples/reader2.zig",
.desc = "Parse and validate an XML file with an xmlReader",
},
.{
.name = "reader3",
.path = "examples/reader3.zig",
.desc = "Show how to extract subdocuments with xmlReader",
.wrapper = true, // For stdout (stdio.h)
},
.{
.name = "reader4",
.path = "examples/reader4.zig",
.desc = "Parse multiple XML files reusing an xmlReader",
},
};
for (examples) |example| {
const exe = b.addExecutable(.{
.name = example.name,
.root_source_file = .{ .path = example.path },
.target = target,
.optimize = optimize,
});
if (example.wrapper) {
exe.addCSourceFile(.{ .file = .{ .path = "examples/wrapper.c" }, .flags = &.{} });
exe.addIncludePath(.{ .path = "." });
}
exe.linkLibrary(lib);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step(example.name, example.desc);
run_step.dependOn(&run_cmd.step);
examples_step.dependOn(&exe.step);
}
}