Skip to content

Commit 8adfb60

Browse files
committed
Fix windows build
1 parent 1c95aae commit 8adfb60

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

build.zig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,33 @@ pub fn build(b: *std.Build) void {
259259
test_all_step.dependOn(integration_test_step);
260260
}
261261

262+
fn addMingwGccArchives(b: *std.Build, lib: *std.Build.Step.Compile, target_info: std.Target) bool {
263+
// Only relevant for Windows targets
264+
if (target_info.os.tag != .windows) return false;
265+
const base_dir = switch (target_info.cpu.arch) {
266+
.x86_64 => "/usr/lib/gcc/x86_64-w64-mingw32",
267+
.x86 => "/usr/lib/gcc/i686-w64-mingw32",
268+
else => return false,
269+
};
270+
271+
var dir = std.fs.openDirAbsolute(base_dir, .{ .iterate = true }) catch return false;
272+
defer dir.close();
273+
var it = dir.iterate();
274+
while (it.next() catch return false) |entry| {
275+
if (entry.kind != .directory) continue;
276+
const ver_dir = std.fmt.allocPrint(b.allocator, "{s}/{s}", .{ base_dir, entry.name }) catch return false;
277+
defer b.allocator.free(ver_dir);
278+
const gcc_eh = std.fmt.allocPrint(b.allocator, "{s}/libgcc_eh.a", .{ ver_dir }) catch return false;
279+
defer b.allocator.free(gcc_eh);
280+
281+
if (std.fs.accessAbsolute(gcc_eh, .{})) |_| {
282+
lib.addObjectFile(.{ .cwd_relative = gcc_eh });
283+
return true;
284+
} else |_| {}
285+
}
286+
return false;
287+
}
288+
262289
fn configurePlatformLibraries(
263290
b: *std.Build,
264291
lib: *std.Build.Step.Compile,
@@ -517,6 +544,8 @@ fn tryConfigureVcpkg(
517544
lib.linkSystemLibrary("zlib"); // vcpkg installs as libzlib.a on Windows
518545
lib.linkSystemLibrary("lzma"); // vcpkg installs as liblzma.a
519546
// Note: deflate library not available in vcpkg mingw-static, skip it
547+
// Explicitly add gcc archives to force resolution if needed
548+
_ = addMingwGccArchives(b, lib, target_info);
520549
} else {
521550
lib.linkSystemLibrary("z");
522551
lib.linkSystemLibrary("lzma");

0 commit comments

Comments
 (0)