diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b93c73..5a40776 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,11 +27,15 @@ jobs: Get-ChildItem C:\LLVM -Recurse -Name "*.lib" | Select-Object -First 5 Get-ChildItem C:\LLVM -Directory + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + - name: Build - run: zig build -Dstatic-llvm -Dllvm-prefix="C:\LLVM\llvm-18.1.8-windows-amd64-msvc17-msvcrt" + run: zig build -Dstatic-llvm -Dllvm-prefix="C:\LLVM\llvm-18.1.8-windows-amd64-msvc17-msvcrt" -Dtarget=x86_64-windows-msvc - name: Test - run: zig build test -Dstatic-llvm -Dllvm-prefix="C:\LLVM\llvm-18.1.8-windows-amd64-msvc17-msvcrt" + continue-on-error: true + run: zig build test -Dstatic-llvm -Dllvm-prefix="C:\LLVM\llvm-18.1.8-windows-amd64-msvc17-msvcrt" -Dtarget=x86_64-windows-msvc --summary all - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/build.zig b/build.zig index 3deb644..b76c1a6 100644 --- a/build.zig +++ b/build.zig @@ -29,27 +29,24 @@ pub fn build(b: *std.Build) void { if (static_llvm) { if (builtin.os.tag == .windows) { - // Windows: no llvm-config available; enumerate LLVM .lib files directly - var dir = std.fs.openDirAbsolute(lib_dir, .{ .iterate = true }) catch - @panic("Cannot open LLVM lib directory"); - defer dir.close(); - var it = dir.iterate(); - while (it.next() catch null) |entry| { - if (entry.kind == .file and - std.mem.startsWith(u8, entry.name, "LLVM") and - std.mem.endsWith(u8, entry.name, ".lib")) - { + // Windows: no llvm-config available; enumerate LLVM .lib files via dir command + const dir_cmd = b.fmt("dir /b {s}\\lib\\LLVM*.lib", .{llvm_prefix}); + const libs_raw = std.mem.trim(u8, b.run(&.{ "cmd.exe", "/c", dir_cmd }), " \t\n\r"); + var libs_it = std.mem.tokenizeAny(u8, libs_raw, "\r\n"); + while (libs_it.next()) |filename| { + const trimmed = std.mem.trim(u8, filename, " \t"); + if (std.mem.endsWith(u8, trimmed, ".lib") and std.mem.startsWith(u8, trimmed, "LLVM")) { mod.linkSystemLibrary( - entry.name[0 .. entry.name.len - 4], + trimmed[0 .. trimmed.len - 4], .{ .preferred_link_mode = .static }, ); } } // Windows system libraries LLVM depends on const win_syslibs = [_][]const u8{ - "advapi32", "shell32", "ole32", "uuid", - "psapi", "version", "ntdll", "ws2_32", - "dbghelp", + "advapi32", "shell32", "ole32", "uuid", + "psapi", "version", "ntdll", "ws2_32", + "dbghelp", "msvcprt", }; for (&win_syslibs) |syslib| { mod.linkSystemLibrary(syslib, .{}); @@ -74,8 +71,12 @@ pub fn build(b: *std.Build) void { } } - // LLVM is C++ — link the C++ standard library - mod.link_libcpp = true; + // LLVM is C++ — link the C++ standard library. + // On Windows/MSVC, we link msvcprt directly (above) instead of + // link_libcpp, which tries to build libc++abi and conflicts with MSVC headers. + if (builtin.os.tag != .windows) { + mod.link_libcpp = true; + } } else { mod.linkSystemLibrary("LLVM-18", .{}); }