Skip to content

Commit ea87f8d

Browse files
committed
link to system provided iconv by default on macOS
It's also possible to avoid the complexity in the documentation by disabling iconv support by default but I would like to keep the same defaults as upstream. I would like to avoid injecting unnecessary opinionated choices into this port.
1 parent d58ab29 commit ea87f8d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ You can then import `libxml2` in your `build.zig` with:
2020
const libxml2_dependency = b.dependency("libxml2", .{
2121
.target = target,
2222
.optimize = optimize,
23+
24+
// libxml2 will try to link to iconv on macOS by default which will
25+
// fail when cross-compiling. You may disable iconv support for or
26+
// link against GNU libiconv which is licensed under LGPL.
27+
28+
// disable iconv support on all targets
29+
// .iconv = false,
30+
31+
// disable iconv support when compiling to macOS
32+
// .iconv = !target.result.os.tag.isDarwin(),
33+
34+
// disable iconv support when cross-compiling to macOS
35+
// .iconv = !(target.query.isNativeOs() and target.result.os.tag.isDarwin()),
36+
37+
// Use GNU libiconv on macOS which is licensed under LGPL.
38+
// .@"iconv-impl" = if (target.result.os.tag.isDarwin()) else null,
2339
});
2440
your_exe.linkLibrary(libxml2_dependency.artifact("xml"));
2541
```

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn build(b: *std.Build) void {
187187
if (http and target.result.os.tag == .windows) xml_lib.root_module.linkSystemLibrary("ws2_32", .{});
188188

189189
if (iconv) {
190-
if (b.systemIntegrationOption("iconv", .{})) {
190+
if (b.systemIntegrationOption("iconv", .{ .default = target.result.os.tag.isDarwin() })) {
191191
xml_lib.root_module.linkSystemLibrary("iconv", .{});
192192
} else {
193193
const IconvImpl = enum { libc, libiconv, win_iconv };

0 commit comments

Comments
 (0)