This commit is contained in:
agra
2026-02-12 10:13:36 +02:00
parent 9a2501f662
commit cfac6791cb
2 changed files with 28 additions and 11 deletions

View File

@@ -19,13 +19,13 @@ jobs:
version: master version: master
- name: Install LLVM 18 - 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 - name: Build
run: zig build -Dstatic-llvm -Dllvm-prefix=/usr/lib/llvm-18 run: zig build -Dllvm-prefix=/usr/lib/llvm-18
- name: Test - 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 - name: Package
run: tar czf sx-linux-x86_64.tar.gz -C zig-out/bin . run: tar czf sx-linux-x86_64.tar.gz -C zig-out/bin .

View File

@@ -27,11 +27,18 @@ pub fn build(b: *std.Build) void {
.flags = &.{b.fmt("-I{s}", .{include_dir})}, .flags = &.{b.fmt("-I{s}", .{include_dir})},
}); });
const target_os = target.result.os.tag;
if (static_llvm) { if (static_llvm) {
if (builtin.os.tag == .windows) { if (target_os == .windows) {
// Windows: no llvm-config available; enumerate LLVM .lib files via dir command // Windows target: enumerate LLVM .lib files in prefix.
const dir_cmd = b.fmt("dir /b {s}\\lib\\LLVM*.lib", .{llvm_prefix}); // Use the host-appropriate command to list files.
const libs_raw = std.mem.trim(u8, b.run(&.{ "cmd.exe", "/c", dir_cmd }), " \t\n\r"); 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"); var libs_it = std.mem.tokenizeAny(u8, libs_raw, "\r\n");
while (libs_it.next()) |filename| { while (libs_it.next()) |filename| {
const trimmed = std.mem.trim(u8, filename, " \t"); const trimmed = std.mem.trim(u8, filename, " \t");
@@ -52,7 +59,7 @@ pub fn build(b: *std.Build) void {
mod.linkSystemLibrary(syslib, .{}); mod.linkSystemLibrary(syslib, .{});
} }
} else { } 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"); 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"); var libs_it = std.mem.tokenizeAny(u8, libs_raw, " \t\n\r");
while (libs_it.next()) |flag| { while (libs_it.next()) |flag| {
@@ -69,12 +76,22 @@ pub fn build(b: *std.Build) void {
mod.linkSystemLibrary(flag[2..], .{}); 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. // LLVM is C++ — link the C++ standard library.
// On Windows/MSVC, we link msvcprt directly (above) instead of // Windows/MSVC: msvcprt already linked above
// link_libcpp, which tries to build libc++abi and conflicts with MSVC headers. // Linux (apt LLVM): compiled with GCC, needs libstdc++
if (builtin.os.tag != .windows) { // macOS (Homebrew LLVM): compiled with Clang, needs libc++
if (target_os == .linux) {
mod.linkSystemLibrary("stdc++", .{});
} else if (target_os != .windows) {
mod.link_libcpp = true; mod.link_libcpp = true;
} }
} else { } else {