Skip to content

Commit a8d82b1

Browse files
committed
allow depending on libiconv or win_iconv
1 parent 3bb874e commit a8d82b1

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,4 @@ jobs:
3333
run: zig fmt --ast-check --check .
3434

3535
- name: Build
36-
if: matrix.os != 'windows-latest'
3736
run: zig build --summary all
38-
39-
- name: Build (windows)
40-
if: matrix.os == 'windows-latest'
41-
run: zig build -Diconv=false --summary all

build.zig

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,44 @@ pub fn build(b: *std.Build) void {
193193
if (history) xml_lib.root_module.linkSystemLibrary("history", .{});
194194
if (lzma) xml_lib.root_module.linkSystemLibrary("lzma", .{});
195195
if (icu) xml_lib.root_module.linkSystemLibrary("icu-i18n", .{});
196-
if (iconv and target.result.os.tag == .windows) xml_lib.root_module.linkSystemLibrary("iconv", .{});
197196
if (target.result.os.tag == .windows) xml_lib.root_module.linkSystemLibrary("bcrypt", .{});
198197
if (http and target.result.os.tag == .windows) xml_lib.root_module.linkSystemLibrary("ws2_32", .{});
199198

199+
if (iconv) {
200+
if (b.systemIntegrationOption("iconv", .{})) {
201+
xml_lib.root_module.linkSystemLibrary("iconv", .{});
202+
} else {
203+
const IconvImpl = enum { libc, libiconv, win_iconv };
204+
const impl: IconvImpl = b.option(
205+
IconvImpl,
206+
"iconv-impl",
207+
"Set the iconv implementation (default=libc except for win_iconv on windows)",
208+
) orelse switch (target.result.os.tag) {
209+
.windows => .win_iconv,
210+
else => .libc,
211+
};
212+
switch (impl) {
213+
.libc => {},
214+
.libiconv => {
215+
if (b.lazyDependency("libiconv", .{
216+
.target = target,
217+
.optimize = optimize,
218+
})) |libiconv_dependency| {
219+
xml_lib.root_module.linkLibrary(libiconv_dependency.artifact("z"));
220+
}
221+
},
222+
.win_iconv => {
223+
if (b.lazyDependency("win_iconv", .{
224+
.target = target,
225+
.optimize = optimize,
226+
})) |win_iconv_dependency| {
227+
xml_lib.root_module.linkLibrary(win_iconv_dependency.artifact("iconv"));
228+
}
229+
},
230+
}
231+
}
232+
}
233+
200234
if (zlib) {
201235
if (b.systemIntegrationOption("zlib", .{})) {
202236
xml_lib.root_module.linkSystemLibrary("zlib", .{});

build.zig.zon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
.hash = "zlib-1.3.1-ZZQ7lVgMAACwO4nUUd8GLhsuQ5JQq_VAhlEiENJTUv6h",
1313
.lazy = true,
1414
},
15+
.libiconv = .{
16+
.url = "git+https://github.com/allyourcodebase/libiconv.git#9def4c8a1743380e85bcedb80f2c15b455e236f3",
17+
.hash = "libiconv-1.18.0-p9sJwWnqAACzVYeWgXB5r5lOQ74XwTPlptixV0JPRO28",
18+
.lazy = true,
19+
},
20+
.win_iconv = .{
21+
.url = "git+https://github.com/allyourcodebase/win-iconv.git#497c381e41437856527b7a00b66e75af3f1f7dcc",
22+
.hash = "win_iconv-0.0.10--19NP7MRAAD3CC0z2Jp2YTy649Q724cYYaR9uL7v7NCh",
23+
.lazy = true,
24+
},
1525
},
1626
.paths = .{
1727
"build.zig",

0 commit comments

Comments
 (0)