@@ -15,134 +15,70 @@ pub fn build(b: *std.Build) void {
15
15
16
16
const minimum = b .option (bool , "minimum" , "build a minimally sized library (default=false)" ) orelse false ;
17
17
const legacy = b .option (bool , "legacy" , "maximum ABI compatibility (default=false)" ) orelse false ;
18
+
19
+ const http = b .option (bool , "http" , "HTTP support (default=false)" ) orelse false ;
20
+ const icu = b .option (bool , "icu" , "ICU support (default=false)" ) orelse false ;
21
+ const lzma = b .option (bool , "lzma" , "use liblzma in DIR (default=false)" ) orelse false ;
22
+ // const python = b.option(bool, "python", "Python bindings (default=false)") orelse false;
23
+ const thread_alloc = b .option (bool , "thread-alloc" , "per-thread malloc hooks (default=false)" ) orelse false ;
18
24
const tls = b .option (bool , "tls" , "thread-local storage (default=false)" ) orelse false ;
19
25
20
- var c14n = b .option (bool , "c14n" , "Canonical XML 1.0 support (default=true)" ) orelse ! minimum ;
21
26
const catalog = b .option (bool , "catalog" , "XML Catalogs support (default=true)" ) orelse ! minimum ;
22
27
const debug = b .option (bool , "debug" , "debugging module (default=true)" ) orelse ! minimum ;
23
- const ftp = b .option (bool , "ftp" , "FTP support (default=false)" ) orelse false ;
24
- const history = b .option (bool , "history" , "history support for xmllint shell (default=false)" ) orelse false ;
25
- var readline = b .option (bool , "readline" , "use readline in DIR for shell (default=off)" ) orelse ! minimum and history ;
26
28
const html = b .option (bool , "html" , "HTML parser (default=true)" ) orelse ! minimum ;
27
- const http = b .option (bool , "http" , "HTTP support (default=false)" ) orelse legacy ;
28
- const iconv = b .option (bool , "iconv" , "iconv support (default=on)" ) orelse ! minimum ;
29
- const icu = b .option (bool , "icu" , "ICU support (default=false)" ) orelse false ;
29
+ const iconv = b .option (bool , "iconv" , "iconv support (default=true)" ) orelse ! minimum ;
30
30
const iso8859x = b .option (bool , "iso8859x" , "ISO-8859-X support if no iconv (default=true)" ) orelse ! minimum ;
31
- const lzma = b .option (bool , "lzma" , "use liblzma in DIR (default=off)" ) orelse legacy ;
32
31
// const modules = b.option(bool, "modules", "dynamic modules support (default=true)") orelse !minimum;
33
- var output = b .option (bool , "output" , "serialization support (default=true)" ) orelse ! minimum ;
34
- var pattern = b .option (bool , "pattern" , "xmlPattern selection interface (default=true)" ) orelse ! minimum ;
35
- var push = b .option (bool , "push" , "push parser interfaces (default=true)" ) orelse ! minimum ;
36
- // const python = b.option(bool, "python", "Python bindings (default=true)") orelse !minimum;
37
- var reader = b .option (bool , "reader" , "xmlReader parsing interface (default=true)" ) orelse ! minimum ;
38
- var regexps = b .option (bool , "regexps" , "regular expressions support (default=true)" ) orelse ! minimum ;
39
32
const sax1 = b .option (bool , "sax1" , "older SAX1 interface (default=true)" ) orelse ! minimum ;
40
- var schemas = b .option (bool , "schemas" , "XML Schemas 1.0 and RELAX NG support (default=true)" ) orelse ! minimum ;
41
- var schematron = b .option (bool , "schematron" , "Schematron support (default=true)" ) orelse ! minimum ;
42
33
const threads = b .option (bool , "threads" , "multithreading support (default=true)" ) orelse ! minimum ;
43
- const thread_alloc = b .option (bool , "thread-alloc" , "per-thread malloc hooks (default=false)" ) orelse false ;
44
34
const valid = b .option (bool , "valid" , "DTD validation support (default=true)" ) orelse ! minimum ;
45
- var writer = b .option (bool , "writer" , "xmlWriter serialization interface (default=true)" ) orelse ! minimum ;
46
- var xinclude = b .option (bool , "xinclude" , "XInclude 1.0 support (default=true)" ) orelse ! minimum ;
47
- var xpath = b .option (bool , "xpath" , "XPath 1.0 support (default=true)" ) orelse ! minimum ;
48
- var xptr = b .option (bool , "xptr" , "XPointer support (default=true)" ) orelse ! minimum ;
49
- const xptr_locs = b .option (bool , "xptr-locs" , "XPointer ranges and points (default=false)" ) orelse false ;
35
+ const xinclude = b .option (bool , "xinclude" , "XInclude 1.0 support (default=true)" ) orelse ! minimum ;
36
+
50
37
const zlib = b .option (bool , "zlib" , "use libz in DIR" ) orelse legacy ;
51
38
52
- if (c14n ) {
53
- if (! output ) {
54
- std .log .warn ("-Dc14n overrides -Doutput=false" , .{});
55
- output = true ;
56
- }
57
- if (! xpath ) {
58
- std .log .warn ("-Dc14n overrides -Dxpath=false" , .{});
59
- xpath = true ;
60
- }
61
- }
62
- if (schemas ) {
63
- if (! pattern ) {
64
- std .log .warn ("-Dschemas overrides -Dpattern=false" , .{});
65
- pattern = true ;
66
- }
67
- if (! regexps ) {
68
- std .log .warn ("-Dschemas overrides -Dregexps=false" , .{});
69
- regexps = true ;
70
- }
71
- }
72
- if (schematron ) {
73
- if (! pattern ) {
74
- std .log .warn ("-Dschematron overrides -Dpattern=false" , .{});
75
- pattern = true ;
76
- }
77
- if (! xpath ) {
78
- std .log .warn ("-Dschematron overrides -Dxpath=false" , .{});
79
- xpath = true ;
80
- }
81
- }
82
- if (reader ) {
83
- if (! push ) {
84
- std .log .warn ("-Dreader overrides -Dpush=false" , .{});
85
- push = true ;
86
- }
87
- }
88
- if (writer ) {
89
- if (! output ) {
90
- std .log .warn ("-Dwriter overrides -Doutput=false" , .{});
91
- output = true ;
92
- }
93
- if (! push ) {
94
- std .log .warn ("-Dwriter overrides -Dpush=false" , .{});
95
- push = true ;
96
- }
97
- }
98
- if (xinclude ) {
99
- if (! xpath ) {
100
- std .log .warn ("-Dxinclude overrides -Dxpath=false" , .{});
101
- xpath = true ;
102
- }
103
- }
104
- if (xptr_locs ) {
105
- if (! xpath ) {
106
- std .log .warn ("-Dxptr-locs overrides -Dxptr=false" , .{});
107
- xpath = true ;
108
- }
109
- }
110
- if (xptr ) {
111
- if (! xpath ) {
112
- std .log .warn ("-Dxptr overrides -Dxpath=false" , .{});
113
- xpath = true ;
114
- }
115
- }
116
- if (history ) {
117
- if (! readline ) {
118
- std .log .warn ("-Dhistory overrides -Dreadline=false" , .{});
119
- readline = true ;
120
- }
121
- }
39
+ const want_c14n = b .option (bool , "c14n" , "Canonical XML 1.0 support (default=true)" );
40
+ const want_history = b .option (bool , "history" , "history support for xmllint shell (default=false)" );
41
+ const want_readline = b .option (bool , "readline" , "use readline in DIR for shell (default=false)" );
42
+ const want_output = b .option (bool , "output" , "serialization support (default=true)" );
43
+ const want_pattern = b .option (bool , "pattern" , "xmlPattern selection interface (default=true)" );
44
+ const want_push = b .option (bool , "push" , "push parser interfaces (default=true)" );
45
+ const want_reader = b .option (bool , "reader" , "xmlReader parsing interface (default=true)" );
46
+ const want_regexps = b .option (bool , "regexps" , "regular expressions support (default=true)" );
47
+ const want_relaxng = b .option (bool , "relaxng" , "RELAX NG support (default=true)" );
48
+ const want_schemas = b .option (bool , "schemas" , "XML Schemas 1.0 and RELAX NG support (default=true)" );
49
+ const want_schematron = b .option (bool , "schematron" , "Schematron support (default=true)" );
50
+ const want_writer = b .option (bool , "writer" , "xmlWriter serialization interface (default=true)" );
51
+ const want_xpath = b .option (bool , "xpath" , "XPath 1.0 support (default=true)" );
52
+ const want_xptr = b .option (bool , "xptr" , "XPointer support (default=true)" );
122
53
123
- if (! minimum ) {
124
- if (! output ) {
125
- c14n = false ;
126
- writer = false ;
127
- }
128
- if (! pattern ) {
129
- schemas = false ;
130
- schematron = false ;
131
- }
132
- if (! push ) {
133
- reader = false ;
134
- writer = false ;
135
- }
136
- if (! regexps ) {
137
- schemas = false ;
138
- }
139
- if (! xpath ) {
140
- c14n = false ;
141
- schematron = false ;
142
- xinclude = false ;
143
- xptr = false ;
144
- }
145
- }
54
+ const output = want_output orelse (! minimum or want_c14n == true or want_writer == true );
55
+ const pattern = want_pattern orelse (! minimum or want_schemas == true or want_schematron == true );
56
+ const regexps = want_regexps orelse (! minimum or want_relaxng == true or want_schemas == true );
57
+ const push = want_push orelse (! minimum or want_reader == true or want_writer == true );
58
+ const readline = want_readline orelse (want_history == true );
59
+ const xpath = want_xpath orelse (! minimum or want_c14n == true or want_schematron == true or want_xptr == true );
60
+
61
+ const c14n = want_c14n orelse (! minimum and output and xpath );
62
+ const history = want_history orelse false ;
63
+ const reader = want_reader orelse (! minimum and push );
64
+ const schemas = want_schemas orelse (! minimum and pattern and regexps );
65
+ const relaxng = want_relaxng orelse (! minimum and schemas );
66
+ const schematron = want_schematron orelse (! minimum and pattern and xpath );
67
+ const writer = want_writer orelse (! minimum and output and push );
68
+ const xptr = want_xptr orelse (! minimum and xpath );
69
+
70
+ if (c14n and ! output ) std .debug .panic ("c14n requires output" , .{});
71
+ if (c14n and ! xpath ) std .debug .panic ("c14n requires xpath" , .{});
72
+ if (history and ! readline ) std .debug .panic ("history requires readline" , .{});
73
+ if (reader and ! push ) std .debug .panic ("reader requires push" , .{});
74
+ if (schemas and ! pattern ) std .debug .panic ("schemas requires pattern" , .{});
75
+ if (schemas and ! regexps ) std .debug .panic ("schemas requires regexps" , .{});
76
+ if (relaxng and ! schemas ) std .debug .panic ("relaxng requires schemas" , .{});
77
+ if (schematron and ! pattern ) std .debug .panic ("schematron requires pattern" , .{});
78
+ if (schematron and ! xpath ) std .debug .panic ("schematron requires xpath" , .{});
79
+ if (writer and ! output ) std .debug .panic ("writer requires output" , .{});
80
+ if (writer and ! push ) std .debug .panic ("writer requires push" , .{});
81
+ if (xptr and ! xpath ) std .debug .panic ("xptr requires xpath" , .{});
146
82
147
83
const xml_version_header = b .addConfigHeader (.{
148
84
.include_path = "libxml/xmlversion.h" ,
@@ -152,15 +88,13 @@ pub fn build(b: *std.Build) void {
152
88
.LIBXML_VERSION_NUMBER = @as (i64 , version .major * 10000 + version .major * 100 + version .patch ),
153
89
.LIBXML_VERSION_EXTRA = "" ,
154
90
.WITH_THREADS = threads ,
155
- .WITH_THREAD_ALLOC = threads and thread_alloc ,
156
- .WITH_TREE = true ,
91
+ .WITH_THREAD_ALLOC = thread_alloc ,
157
92
.WITH_OUTPUT = output ,
158
93
.WITH_PUSH = push ,
159
94
.WITH_READER = reader ,
160
95
.WITH_PATTERN = pattern ,
161
96
.WITH_WRITER = writer ,
162
97
.WITH_SAX1 = sax1 ,
163
- .WITH_FTP = ftp ,
164
98
.WITH_HTTP = http ,
165
99
.WITH_VALID = valid ,
166
100
.WITH_HTML = html ,
@@ -169,13 +103,13 @@ pub fn build(b: *std.Build) void {
169
103
.WITH_CATALOG = catalog ,
170
104
.WITH_XPATH = xpath ,
171
105
.WITH_XPTR = xptr ,
172
- .WITH_XPTR_LOCS = xptr_locs ,
173
106
.WITH_XINCLUDE = xinclude ,
174
107
.WITH_ICONV = iconv ,
175
108
.WITH_ICU = icu ,
176
109
.WITH_ISO8859X = iso8859x ,
177
110
.WITH_DEBUG = debug ,
178
111
.WITH_REGEXPS = regexps ,
112
+ .WITH_RELAXNG = relaxng ,
179
113
.WITH_SCHEMAS = schemas ,
180
114
.WITH_SCHEMATRON = schematron ,
181
115
.WITH_MODULES = false ,
@@ -185,23 +119,33 @@ pub fn build(b: *std.Build) void {
185
119
});
186
120
187
121
const config_header = b .addConfigHeader (.{}, .{
122
+ .HAVE_DECL_GETENTROPY = switch (target .result .os .tag ) {
123
+ .linux = > target .result .isGnuLibC () and target .result .os .version_range .linux .glibc .order (.{ .major = 2 , .minor = 25 , .patch = 0 }) != .lt ,
124
+ .freebsd , .openbsd = > true ,
125
+ else = > target .result .os .tag .isDarwin (),
126
+ },
127
+ .HAVE_DECL_GLOB = target .result .os .tag != .windows ,
128
+ .HAVE_DECL_MMAP = target .result .os .tag != .windows and target .result .os .tag != .wasi ,
129
+ .HAVE_DLFCN_H = target .result .os .tag != .windows ,
130
+ .HAVE_DLOPEN = false , // only present if `WITH_MODULES`
131
+ .HAVE_FUNC_ATTRIBUTE_DESTRUCTOR = true ,
132
+ .HAVE_INTTYPES_H = true ,
133
+ .HAVE_LIBHISTORY = history ,
134
+ .HAVE_LIBREADLINE = readline ,
135
+ .HAVE_LZMA_H = lzma ,
136
+ .HAVE_POLL_H = http and target .result .os .tag != .windows ,
137
+ .HAVE_PTHREAD_H = target .result .os .tag != .windows ,
138
+ .HAVE_SHLLOAD = false , // only present if `WITH_MODULES`
188
139
.HAVE_STDINT_H = true ,
189
- .HAVE_FCNTL_H = true ,
190
- .HAVE_UNISTD_H = true ,
140
+ .HAVE_STDIO_H = target .result .os .tag != .wasi ,
141
+ .HAVE_STDLIB_H = target .result .os .tag != .wasi ,
142
+ .HAVE_STRINGS_H = target .result .os .tag != .wasi ,
143
+ .HAVE_STRING_H = target .result .os .tag != .wasi ,
191
144
.HAVE_SYS_STAT_H = true ,
192
- .HAVE_SYS_MMAN_H = true ,
193
- .HAVE_SYS_TIME_H = true ,
194
- .HAVE_SYS_TIMEB_H = true ,
195
- .HAVE_SYS_RANDOM_H = true ,
196
- .HAVE_DL_H = true ,
197
- .HAVE_DLFCN_H = true ,
198
- .HAVE_GLOB_H = true ,
199
- .HAVE_DECL_GETENTROPY = true ,
200
- .HAVE_DECL_GLOB = true ,
201
- .HAVE_DECL_MMAP = true ,
202
- .HAVE_POLL_H = true ,
203
- .HAVE_ATTRIBUTE_DESTRUCTOR = true ,
204
- .ATTRIBUTE_DESTRUCTOR = .@"__attribute__((destructor))" ,
145
+ .HAVE_SYS_TYPES_H = target .result .os .tag != .wasi ,
146
+ .HAVE_UNISTD_H = target .result .os .tag != .wasi ,
147
+ .HAVE_ZLIB_H = zlib ,
148
+ .XML_SYSCONFDIR = if (catalog ) "" else null , // TODO
205
149
});
206
150
if (tls ) {
207
151
config_header .addValues (.{ .XML_THREAD_LOCAL = ._Thread_local });
@@ -220,47 +164,49 @@ pub fn build(b: *std.Build) void {
220
164
}),
221
165
});
222
166
b .installArtifact ((xml_lib ));
167
+ xml_lib .installHeader (xml_version_header .getOutput (), "libxml/xmlversion.h" );
168
+ xml_lib .installHeadersDirectory (upstream .path ("include/libxml" ), "libxml" , .{});
223
169
xml_lib .root_module .addConfigHeader (config_header );
224
170
xml_lib .root_module .addConfigHeader (xml_version_header );
225
- xml_lib .installHeader (xml_version_header .getOutput (), "libxml/xmlversion.h" );
226
171
xml_lib .root_module .addIncludePath (upstream .path ("include" ));
227
172
xml_lib .root_module .addCSourceFiles (.{ .files = xml_src , .root = upstream .path ("" ), .flags = xml_flags });
228
- xml_lib .installHeadersDirectory (upstream .path ("include/libxml" ), "libxml" , .{});
229
- if (target .result .os .tag != .windows ) xml_lib .root_module .addCMacro ("HAVE_PTHREAD_H" , "1" );
230
- if (target .result .os .tag == .windows ) xml_lib .root_module .addCMacro ("LIBXML_STATIC" , "1" );
173
+ if (target .result .os .tag == .windows and linkage == .static ) xml_lib .root_module .addCMacro ("LIBXML_STATIC" , "1" );
231
174
if (c14n ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("c14n.c" ), .flags = xml_flags });
232
175
if (catalog ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("catalog.c" ), .flags = xml_flags });
233
176
if (debug ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("debugXML.c" ), .flags = xml_flags });
234
- if (ftp ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("nanoftp.c" ), .flags = xml_flags });
235
177
if (html ) xml_lib .root_module .addCSourceFiles (.{ .files = &.{ "HTMLparser.c" , "HTMLtree.c" }, .root = upstream .path ("" ), .flags = xml_flags });
236
178
if (http ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("nanohttp.c" ), .flags = xml_flags });
237
- if (legacy ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("legacy.c" ), .flags = xml_flags });
238
179
if (lzma ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("xzlib.c" ), .flags = xml_flags });
239
180
// if (modules) xml_lib.root_module.addCSourceFile(.{ .file = upstream.path("xmlmodule.c"), .flags = xml_flags });
240
181
if (output ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("xmlsave.c" ), .flags = xml_flags });
241
182
if (pattern ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("pattern.c" ), .flags = xml_flags });
242
183
if (reader ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("xmlreader.c" ), .flags = xml_flags });
243
- if (regexps ) xml_lib .root_module .addCSourceFiles (.{ .files = &.{ "xmlregexp.c" , "xmlunicode.c" }, .root = upstream .path ("" ), .flags = xml_flags });
244
- if (schemas ) xml_lib .root_module .addCSourceFiles (.{ .files = &.{ "relaxng.c" , "xmlschemas.c" , "xmlschemastypes.c" }, .root = upstream .path ("" ), .flags = xml_flags });
184
+ if (regexps ) xml_lib .root_module .addCSourceFiles (.{ .files = &.{"xmlregexp.c" }, .root = upstream .path ("" ), .flags = xml_flags });
185
+ if (relaxng ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("relaxng.c" ), .flags = xml_flags });
186
+ if (schemas ) xml_lib .root_module .addCSourceFiles (.{ .files = &.{ "xmlschemas.c" , "xmlschemastypes.c" }, .root = upstream .path ("" ), .flags = xml_flags });
245
187
if (schematron ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("schematron.c" ), .flags = xml_flags });
246
188
if (writer ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("xmlwriter.c" ), .flags = xml_flags });
247
189
if (xinclude ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("xinclude.c" ), .flags = xml_flags });
248
190
if (xpath ) xml_lib .root_module .addCSourceFile (.{ .file = upstream .path ("xpath.c" ), .flags = xml_flags });
249
191
if (xptr ) xml_lib .root_module .addCSourceFiles (.{ .files = &.{ "xlink.c" , "xpointer.c" }, .root = upstream .path ("" ), .flags = xml_flags });
250
- if (readline ) {
251
- xml_lib .root_module .linkSystemLibrary ("readline" , .{});
252
- xml_lib .root_module .addCMacro ("HAVE_LIBREADLINE" , "1" );
253
- }
254
- if (history ) {
255
- xml_lib .root_module .linkSystemLibrary ("history" , .{});
256
- xml_lib .root_module .addCMacro ("HAVE_LIBHISTORY" , "1" );
257
- }
258
- if (zlib ) xml_lib .root_module .linkSystemLibrary ("zlib" , .{});
192
+ if (readline ) xml_lib .root_module .linkSystemLibrary ("readline" , .{});
193
+ if (history ) xml_lib .root_module .linkSystemLibrary ("history" , .{});
259
194
if (lzma ) xml_lib .root_module .linkSystemLibrary ("lzma" , .{});
260
195
if (icu ) xml_lib .root_module .linkSystemLibrary ("icu-i18n" , .{});
261
- if (iconv ) xml_lib .root_module .linkSystemLibrary ("iconv" , .{});
196
+ // if (iconv) xml_lib.root_module.linkSystemLibrary("iconv", .{});
262
197
if (target .result .os .tag == .windows ) xml_lib .root_module .linkSystemLibrary ("bcrypt" , .{});
263
198
if (http and target .result .os .tag == .windows ) xml_lib .root_module .linkSystemLibrary ("ws2_32" , .{});
199
+
200
+ if (zlib ) {
201
+ if (b .systemIntegrationOption ("zlib" , .{})) {
202
+ xml_lib .root_module .linkSystemLibrary ("zlib" , .{});
203
+ } else if (b .lazyDependency ("zlib" , .{
204
+ .target = target ,
205
+ .optimize = optimize ,
206
+ })) | zlib_dependency | {
207
+ xml_lib .root_module .linkLibrary (zlib_dependency .artifact ("z" ));
208
+ }
209
+ }
264
210
}
265
211
266
212
pub const xml_src : []const []const u8 = &.{
0 commit comments