...
This commit is contained in:
33
build.zig
33
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 {
|
||||
|
||||
Reference in New Issue
Block a user