From 350a88ddf4869d35391b6bb985f41a21931795b7 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Sat, 8 Oct 2022 13:15:49 -0700 Subject: [PATCH 1/2] build.zig: Forward LLVM lib/include dirs from CMake Previously, you might obtain `-lLLVM-15` from the CMake configuration, but we might not be able to locate the library if it's not in your system library path. --- build.zig | 14 ++++++++++++++ src/stage1/config.h.in | 2 ++ 2 files changed, 16 insertions(+) diff --git a/build.zig b/build.zig index fcdf569e48..13e9fa1134 100644 --- a/build.zig +++ b/build.zig @@ -554,6 +554,8 @@ fn addCmakeCfgOptionsToExe( }) catch unreachable); assert(cfg.lld_include_dir.len != 0); exe.addIncludePath(cfg.lld_include_dir); + exe.addIncludePath(cfg.llvm_include_dir); + exe.addLibraryPath(cfg.llvm_lib_dir); addCMakeLibraryList(exe, cfg.clang_libraries); addCMakeLibraryList(exe, cfg.lld_libraries); addCMakeLibraryList(exe, cfg.llvm_libraries); @@ -684,6 +686,8 @@ const CMakeConfig = struct { lld_include_dir: []const u8, lld_libraries: []const u8, clang_libraries: []const u8, + llvm_lib_dir: []const u8, + llvm_include_dir: []const u8, llvm_libraries: []const u8, dia_guids_lib: []const u8, }; @@ -745,6 +749,8 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { .lld_include_dir = undefined, .lld_libraries = undefined, .clang_libraries = undefined, + .llvm_lib_dir = undefined, + .llvm_include_dir = undefined, .llvm_libraries = undefined, .dia_guids_lib = undefined, }; @@ -782,6 +788,14 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { .prefix = "#define ZIG_DIA_GUIDS_LIB ", .field = "dia_guids_lib", }, + .{ + .prefix = "#define ZIG_LLVM_INCLUDE_PATH ", + .field = "llvm_include_dir", + }, + .{ + .prefix = "#define ZIG_LLVM_LIB_PATH ", + .field = "llvm_lib_dir", + }, // .prefix = ZIG_LLVM_LINK_MODE parsed manually below }; diff --git a/src/stage1/config.h.in b/src/stage1/config.h.in index 2be0839996..8d1e688cbe 100644 --- a/src/stage1/config.h.in +++ b/src/stage1/config.h.in @@ -22,6 +22,8 @@ #define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@" #define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@" #define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@" +#define ZIG_LLVM_INCLUDE_PATH "@LLVM_INCLUDE_DIRS@" +#define ZIG_LLVM_LIB_PATH "@LLVM_LIBDIRS@" #define ZIG_LLVM_LIBRARIES "@LLVM_LIBRARIES@" #define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@" From 50a6dc8496c7c4ccb1ac30ad53da524dd3161c15 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Tue, 11 Oct 2022 08:16:27 -0700 Subject: [PATCH 2/2] build.zig: Parse CMAKE_PREFIX_PATH with multiple entries CMAKE_PREFIX_PATH is a semicolon separated list. --- build.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 13e9fa1134..7b5cc30605 100644 --- a/build.zig +++ b/build.zig @@ -339,7 +339,10 @@ pub fn build(b: *Builder) !void { // That means we also have to rely on stage1 compiled c++ files. We parse config.h to find // the information passed on to us from cmake. if (cfg.cmake_prefix_path.len > 0) { - b.addSearchPrefix(cfg.cmake_prefix_path); + var it = mem.tokenize(u8, cfg.cmake_prefix_path, ";"); + while (it.next()) |path| { + b.addSearchPrefix(path); + } } try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);