From 3df62ed766ff20ee100bece2636348720fc468b9 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 8 Nov 2023 21:04:08 +0100 Subject: [PATCH] build: only add llvm library path if its not a native path --- build.zig | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 5a544bfda742..e2fab3791b26 100644 --- a/build.zig +++ b/build.zig @@ -9,6 +9,7 @@ const fs = std.fs; const InstallDirectoryOptions = std.Build.InstallDirectoryOptions; const assert = std.debug.assert; const GenerateDef = @import("deps/aro/build/GenerateDef.zig"); +const NativePaths = std.zig.system.NativePaths; const zig_version = std.SemanticVersion{ .major = 0, .minor = 12, .patch = 0 }; const stack_size = 32 * 1024 * 1024; @@ -633,10 +634,25 @@ fn addCmakeCfgOptionsToExe( cfg.cmake_static_library_suffix, }), }) }); + + const add_llvm_lib_dir = blk: { + const native_paths = NativePaths.detect(b.allocator, exe.target_info) catch { + break :blk true; + }; + + for (native_paths.lib_dirs.items) |lib_dir| { + if (mem.eql(u8, lib_dir, cfg.llvm_lib_dir)) + break :blk false; + } + + break :blk true; + }; + assert(cfg.lld_include_dir.len != 0); exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir }); exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir }); - exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); + if (add_llvm_lib_dir) + exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); addCMakeLibraryList(exe, cfg.clang_libraries); addCMakeLibraryList(exe, cfg.lld_libraries); addCMakeLibraryList(exe, cfg.llvm_libraries);