|
| 1 | +diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 2 | +index c9ff3696e22d..bd96aab5e237 100644 |
| 3 | +--- a/CMakeLists.txt |
| 4 | ++++ b/CMakeLists.txt |
| 5 | +@@ -1133,9 +1133,9 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "") |
| 6 | + add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src |
| 7 | + ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) |
| 8 | + install(TARGETS tf_xla_runtime EXPORT LLVMExports |
| 9 | +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) |
| 10 | ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) |
| 11 | + install(TARGETS tf_xla_runtime EXPORT LLVMDevelopmentExports |
| 12 | +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) |
| 13 | ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) |
| 14 | + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) |
| 15 | + # Once we add more modules, we should handle this more automatically. |
| 16 | + if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) |
| 17 | +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake |
| 18 | +index baf47677b247..81954240a9bf 100644 |
| 19 | +--- a/cmake/modules/AddLLVM.cmake |
| 20 | ++++ b/cmake/modules/AddLLVM.cmake |
| 21 | +@@ -974,8 +974,8 @@ macro(add_llvm_library name) |
| 22 | + endif() |
| 23 | + install(TARGETS ${name} |
| 24 | + ${export_to_llvmexports} |
| 25 | +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} |
| 26 | +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} |
| 27 | ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} |
| 28 | ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} |
| 29 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) |
| 30 | + |
| 31 | + if (NOT LLVM_ENABLE_IDE) |
| 32 | +@@ -2240,7 +2240,7 @@ function(llvm_install_library_symlink name dest type) |
| 33 | + set(LLVM_LINK_OR_COPY copy) |
| 34 | + endif() |
| 35 | + |
| 36 | +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) |
| 37 | ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) |
| 38 | + if(WIN32 AND "${type}" STREQUAL "SHARED") |
| 39 | + set(output_dir "${CMAKE_INSTALL_BINDIR}") |
| 40 | + endif() |
| 41 | +@@ -2516,15 +2516,37 @@ function(llvm_setup_rpath name) |
| 42 | + |
| 43 | + if (APPLE) |
| 44 | + set(_install_name_dir INSTALL_NAME_DIR "@rpath") |
| 45 | +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) |
| 46 | ++ set(_install_rpath ${extra_libdir}) |
| 47 | + elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) |
| 48 | + # $ORIGIN is not interpreted at link time by aix ld. |
| 49 | + # Since BUILD_SHARED_LIBS is only recommended for use by developers, |
| 50 | + # hardcode the rpath to build/install lib dir first in this mode. |
| 51 | + # FIXME: update this when there is better solution. |
| 52 | +- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) |
| 53 | ++ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) |
| 54 | + elseif(UNIX) |
| 55 | +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) |
| 56 | ++ # Note that we add `extra_libdir` (aka `LLVM_LIBRARY_DIR` in our case) back |
| 57 | ++ # to `_install_rpath` here. |
| 58 | ++ # |
| 59 | ++ # In nixpkgs we do not build and install LLVM alongside rdeps of LLVM (i.e. |
| 60 | ++ # clang); instead LLVM is its own package and thus lands at its own nix |
| 61 | ++ # store path. This makes it so that the default relative rpath (`../lib/`) |
| 62 | ++ # does not point at the LLVM shared objects. |
| 63 | ++ # |
| 64 | ++ # More discussion here: |
| 65 | ++ # - https://github.com/NixOS/nixpkgs/pull/235624#discussion_r1220150329 |
| 66 | ++ # - https://reviews.llvm.org/D146918 (16.0.5+) |
| 67 | ++ # |
| 68 | ++ # Note that we leave `extra_libdir` in `_build_rpath`: without FHS there is |
| 69 | ++ # no potential that this will result in us pulling in the "wrong" LLVM. |
| 70 | ++ # Adding this to the build rpath means we aren't forced to use |
| 71 | ++ # `installCheckPhase` instead of `checkPhase` (i.e. binaries in the build |
| 72 | ++ # dir, pre-install, will have the right rpath for LLVM). |
| 73 | ++ # |
| 74 | ++ # As noted in the differential above, an alternative solution is to have |
| 75 | ++ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set |
| 76 | ++ # `CMAKE_INSTALL_RPATH`. |
| 77 | ++ set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) |
| 78 | ++ set(_install_rpath ${extra_libdir}) |
| 79 | + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") |
| 80 | + set_property(TARGET ${name} APPEND_STRING PROPERTY |
| 81 | + LINK_FLAGS " -Wl,-z,origin ") |
| 82 | +@@ -2539,9 +2561,9 @@ function(llvm_setup_rpath name) |
| 83 | + endif() |
| 84 | + |
| 85 | + # Enable BUILD_WITH_INSTALL_RPATH unless CMAKE_BUILD_RPATH is set. |
| 86 | +- if("${CMAKE_BUILD_RPATH}" STREQUAL "") |
| 87 | +- set_property(TARGET ${name} PROPERTY BUILD_WITH_INSTALL_RPATH ON) |
| 88 | +- endif() |
| 89 | ++ #if("${CMAKE_BUILD_RPATH}" STREQUAL "") |
| 90 | ++ # set_property(TARGET ${name} PROPERTY BUILD_WITH_INSTALL_RPATH ON) |
| 91 | ++ #endif() |
| 92 | + |
| 93 | + set_target_properties(${name} PROPERTIES |
| 94 | + INSTALL_RPATH "${_install_rpath}" |
| 95 | +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake |
| 96 | +index 2d9116b08a52..2dd7cad4ec66 100644 |
| 97 | +--- a/cmake/modules/AddOCaml.cmake |
| 98 | ++++ b/cmake/modules/AddOCaml.cmake |
| 99 | +@@ -147,9 +147,9 @@ function(add_ocaml_library name) |
| 100 | + endforeach() |
| 101 | + |
| 102 | + if( APPLE ) |
| 103 | +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") |
| 104 | ++ set(ocaml_rpath ${LLVM_LIBRARY_DIR}) |
| 105 | + elseif( UNIX ) |
| 106 | +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") |
| 107 | ++ set(ocaml_rpath ${LLVM_LIBRARY_DIR}) |
| 108 | + endif() |
| 109 | + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") |
| 110 | + |
| 111 | +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt |
| 112 | +index ef4cfa3acdb5..7478e157a7c2 100644 |
| 113 | +--- a/cmake/modules/CMakeLists.txt |
| 114 | ++++ b/cmake/modules/CMakeLists.txt |
| 115 | +@@ -130,7 +130,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS |
| 116 | + ) |
| 117 | + list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) |
| 118 | + |
| 119 | +-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") |
| 120 | ++extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") |
| 121 | + set(LLVM_CONFIG_LIBRARY_DIRS |
| 122 | + "${LLVM_CONFIG_LIBRARY_DIR}" |
| 123 | + # FIXME: Should there be other entries here? |
| 124 | +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in |
| 125 | +index 370005cd8d7d..7e790bc52111 100644 |
| 126 | +--- a/tools/llvm-config/BuildVariables.inc.in |
| 127 | ++++ b/tools/llvm-config/BuildVariables.inc.in |
| 128 | +@@ -23,6 +23,7 @@ |
| 129 | + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" |
| 130 | + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" |
| 131 | + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" |
| 132 | ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" |
| 133 | + #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" |
| 134 | + #define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@" |
| 135 | + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" |
| 136 | +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp |
| 137 | +index d5b76b1bb6c1..1dbdb2a8f10d 100644 |
| 138 | +--- a/tools/llvm-config/llvm-config.cpp |
| 139 | ++++ b/tools/llvm-config/llvm-config.cpp |
| 140 | +@@ -366,7 +366,11 @@ int main(int argc, char **argv) { |
| 141 | + sys::fs::make_absolute(ActivePrefix, Path); |
| 142 | + ActiveBinDir = std::string(Path); |
| 143 | + } |
| 144 | +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; |
| 145 | ++ { |
| 146 | ++ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); |
| 147 | ++ sys::fs::make_absolute(ActivePrefix, Path); |
| 148 | ++ ActiveLibDir = std::string(Path); |
| 149 | ++ } |
| 150 | + { |
| 151 | + SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR); |
| 152 | + sys::fs::make_absolute(ActivePrefix, Path); |
0 commit comments