From cfac6791cbf78691f958d406aad083630309becc Mon Sep 17 00:00:00 2001 From: agra Date: Thu, 12 Feb 2026 10:13:36 +0200 Subject: [PATCH] ... --- .github/workflows/build.yml | 6 +++--- build.zig | 33 +++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b65c130..fdf72dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,13 +19,13 @@ jobs: version: master - name: Install LLVM 18 - run: sudo apt-get update && sudo apt-get install -y llvm-18-dev + run: sudo apt-get update && sudo apt-get install -y llvm-18-dev gcc - name: Build - run: zig build -Dstatic-llvm -Dllvm-prefix=/usr/lib/llvm-18 + run: zig build -Dllvm-prefix=/usr/lib/llvm-18 - name: Test - run: zig build test -Dstatic-llvm -Dllvm-prefix=/usr/lib/llvm-18 --summary all + run: zig build test -Dllvm-prefix=/usr/lib/llvm-18 --summary all - name: Package run: tar czf sx-linux-x86_64.tar.gz -C zig-out/bin . diff --git a/build.zig b/build.zig index b76c1a6..6d9c287 100644 --- a/build.zig +++ b/build.zig @@ -27,11 +27,18 @@ pub fn build(b: *std.Build) void { .flags = &.{b.fmt("-I{s}", .{include_dir})}, }); + const target_os = target.result.os.tag; + if (static_llvm) { - if (builtin.os.tag == .windows) { - // 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"); + if (target_os == .windows) { + // Windows target: enumerate LLVM .lib files in prefix. + // Use the host-appropriate command to list files. + const libs_raw = if (builtin.os.tag == .windows) blk: { + const dir_cmd = b.fmt("dir /b {s}\\lib\\LLVM*.lib", .{llvm_prefix}); + break :blk std.mem.trim(u8, b.run(&.{ "cmd.exe", "/c", dir_cmd }), " \t\n\r"); + } else blk: { + break :blk std.mem.trim(u8, b.run(&.{ "ls", lib_dir }), " \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"); @@ -52,7 +59,7 @@ pub fn build(b: *std.Build) void { mod.linkSystemLibrary(syslib, .{}); } } else { - // Unix: query llvm-config for the static libraries needed + // Unix target: query llvm-config for the static libraries needed const libs_raw = std.mem.trim(u8, b.run(&.{ llvm_config, "--libs", "--link-static" }), " \t\n\r"); var libs_it = std.mem.tokenizeAny(u8, libs_raw, " \t\n\r"); while (libs_it.next()) |flag| { @@ -69,12 +76,22 @@ pub fn build(b: *std.Build) void { mod.linkSystemLibrary(flag[2..], .{}); } } + + // On Linux, add the multiarch system library directory so LLVM's + // system-lib dependencies (zstd, tinfo, xml2) are found by the linker. + if (builtin.os.tag == .linux) { + const multiarch = @tagName(builtin.cpu.arch) ++ "-linux-gnu"; + mod.addLibraryPath(.{ .cwd_relative = "/usr/lib/" ++ multiarch }); + } } // 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) { + // Windows/MSVC: msvcprt already linked above + // Linux (apt LLVM): compiled with GCC, needs libstdc++ + // macOS (Homebrew LLVM): compiled with Clang, needs libc++ + if (target_os == .linux) { + mod.linkSystemLibrary("stdc++", .{}); + } else if (target_os != .windows) { mod.link_libcpp = true; } } else {