@@ -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" , .{});
0 commit comments