llvmPackages_{13,15,16,17,18,19,git}.llvm: commonify patches

This commit is contained in:
Tristan Ross 2024-08-09 13:30:24 -07:00
parent f95daad5d4
commit 7b4be56d9c
No known key found for this signature in database
GPG Key ID: B09C422035669AF8
20 changed files with 32 additions and 865 deletions

View File

@ -1,105 +0,0 @@
diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt
index ca7c04c565bb..6ed5db5dd4f8 100644
--- a/tools/polly/CMakeLists.txt
+++ b/tools/polly/CMakeLists.txt
@@ -2,7 +2,11 @@
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
project(Polly)
cmake_minimum_required(VERSION 3.13.4)
+endif()
+
+include(GNUInstallDirs)
+if (NOT DEFINED LLVM_MAIN_SRC_DIR)
# Where is LLVM installed?
find_package(LLVM CONFIG REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
@@ -122,13 +126,13 @@ include_directories(
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(DIRECTORY include/
- DESTINATION include
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
)
install(DIRECTORY ${POLLY_BINARY_DIR}/include/
- DESTINATION include
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
PATTERN "CMakeFiles" EXCLUDE
diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt
index 7cc129ba2e90..137be25e4b80 100644
--- a/tools/polly/cmake/CMakeLists.txt
+++ b/tools/polly/cmake/CMakeLists.txt
@@ -79,18 +79,18 @@ file(GENERATE
# Generate PollyConfig.cmake for the install tree.
unset(POLLY_EXPORTS)
-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
+set(POLLY_INSTALL_PREFIX "")
set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
+set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
+set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
if (POLLY_BUNDLED_ISL)
set(POLLY_CONFIG_INCLUDE_DIRS
- "${POLLY_INSTALL_PREFIX}/include"
- "${POLLY_INSTALL_PREFIX}/include/polly"
+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}"
+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly"
)
else()
set(POLLY_CONFIG_INCLUDE_DIRS
- "${POLLY_INSTALL_PREFIX}/include"
+ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}"
${ISL_INCLUDE_DIRS}
)
endif()
@@ -100,12 +100,12 @@ endif()
foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
get_target_property(tgt_type ${tgt} TYPE)
if (tgt_type STREQUAL "EXECUTABLE")
- set(tgt_prefix "bin/")
+ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/")
else()
- set(tgt_prefix "lib/")
+ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/")
endif()
- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$<TARGET_FILE_NAME:${tgt}>")
+ set(tgt_path "${tgt_prefix}$<TARGET_FILE_NAME:${tgt}>")
file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path})
if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake
index 518a09b45a42..bd9d6f5542ad 100644
--- a/tools/polly/cmake/polly_macros.cmake
+++ b/tools/polly/cmake/polly_macros.cmake
@@ -44,8 +44,8 @@ macro(add_polly_library name)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
install(TARGETS ${name}
EXPORT LLVMExports
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endmacro(add_polly_library)
diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt
index 8991094d92c7..178d8ad606bb 100644
--- a/tools/polly/lib/External/CMakeLists.txt
+++ b/tools/polly/lib/External/CMakeLists.txt
@@ -275,7 +275,7 @@ if (POLLY_BUNDLED_ISL)
install(DIRECTORY
${ISL_SOURCE_DIR}/include/
${ISL_BINARY_DIR}/include/
- DESTINATION include/polly
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly
FILES_MATCHING
PATTERN "*.h"
PATTERN "CMakeFiles" EXCLUDE

View File

@ -1,19 +0,0 @@
This is the one remaining Polly install dirs related change that hasn't made it
into upstream yet; previously this patch file also included:
https://reviews.llvm.org/D117541
diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake
index 518a09b45a42..bd9d6f5542ad 100644
--- a/tools/polly/cmake/polly_macros.cmake
+++ b/tools/polly/cmake/polly_macros.cmake
@@ -44,8 +44,8 @@ macro(add_polly_library name)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
install(TARGETS ${name}
EXPORT LLVMExports
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endmacro(add_polly_library)

View File

@ -1,19 +0,0 @@
This is the one remaining Polly install dirs related change that hasn't made it
into upstream yet; previously this patch file also included:
https://reviews.llvm.org/D117541
diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake
index 518a09b45a42..bd9d6f5542ad 100644
--- a/tools/polly/cmake/polly_macros.cmake
+++ b/tools/polly/cmake/polly_macros.cmake
@@ -44,8 +44,8 @@ macro(add_polly_library name)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
install(TARGETS ${name}
EXPORT LLVMExports
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endmacro(add_polly_library)

View File

@ -1,24 +0,0 @@
diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg
index 41e3a589c61e..09f3b17498b0 100644
--- a/tools/polly/test/lit.cfg
+++ b/tools/polly/test/lit.cfg
@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']]
path = os.path.pathsep.join(base_paths + config.extra_paths)
config.environment['PATH'] = path
+# (Copied from polly/test/Unit/lit.cfg)
+if platform.system() == 'Darwin':
+ shlibpath_var = 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+ shlibpath_var = 'PATH'
+else:
+ shlibpath_var = 'LD_LIBRARY_PATH'
+
path = os.path.pathsep.join((config.llvm_libs_dir,
- config.environment.get('LD_LIBRARY_PATH','')))
-config.environment['LD_LIBRARY_PATH'] = path
+ config.environment.get(shlibpath_var,'')))
+config.environment[shlibpath_var] = path
llvm_config.use_default_substitutions()

View File

@ -1,19 +0,0 @@
This is the one remaining Polly install dirs related change that hasn't made it
into upstream yet; previously this patch file also included:
https://reviews.llvm.org/D117541
diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake
index 518a09b45a42..bd9d6f5542ad 100644
--- a/tools/polly/cmake/polly_macros.cmake
+++ b/tools/polly/cmake/polly_macros.cmake
@@ -44,8 +44,8 @@ macro(add_polly_library name)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
install(TARGETS ${name}
EXPORT LLVMExports
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endmacro(add_polly_library)

View File

@ -1,17 +0,0 @@
diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py
index 0242e0b75af3..d732011306f7 100644
--- a/utils/lit/lit/TestRunner.py
+++ b/utils/lit/lit/TestRunner.py
@@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
f.write('@echo off\n')
f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands))
else:
+ # This env var is *purged* when invoking subprocesses so we have to
+ # manually set it from within the bash script in order for the commands
+ # in run lines to see this var:
+ if "DYLD_LIBRARY_PATH" in test.config.environment:
+ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n')
+
for i, ln in enumerate(commands):
match = re.match(kPdbgRegex, ln)
if match:

View File

@ -1,24 +0,0 @@
diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg
index 41e3a589c61e..09f3b17498b0 100644
--- a/tools/polly/test/lit.cfg
+++ b/tools/polly/test/lit.cfg
@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']]
path = os.path.pathsep.join(base_paths + config.extra_paths)
config.environment['PATH'] = path
+# (Copied from polly/test/Unit/lit.cfg)
+if platform.system() == 'Darwin':
+ shlibpath_var = 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+ shlibpath_var = 'PATH'
+else:
+ shlibpath_var = 'LD_LIBRARY_PATH'
+
path = os.path.pathsep.join((config.llvm_libs_dir,
- config.environment.get('LD_LIBRARY_PATH','')))
-config.environment['LD_LIBRARY_PATH'] = path
+ config.environment.get(shlibpath_var,'')))
+config.environment[shlibpath_var] = path
llvm_config.use_default_substitutions()

View File

@ -1,80 +0,0 @@
diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py
index 81e8dc04acea..479ff95681e2 100644
--- a/test/Unit/lit.cfg.py
+++ b/test/Unit/lit.cfg.py
@@ -3,6 +3,7 @@
# Configuration file for the 'lit' test runner.
import os
+import platform
import subprocess
import lit.formats
@@ -55,3 +56,26 @@ if sys.platform in ["win32", "cygwin"] and os.path.isdir(config.shlibdir):
# Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate.
if sys.platform == "win32" and "SYSTEMDRIVE" in os.environ:
config.environment["SYSTEMDRIVE"] = os.environ["SYSTEMDRIVE"]
+
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+ yield "LD_LIBRARY_PATH"
+ elif platform.system() == "Darwin":
+ yield "DYLD_LIBRARY_PATH"
+ elif platform.system() == "Windows":
+ yield "PATH"
+ elif platform.system() == "AIX":
+ yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+ shlibpath = os.path.pathsep.join(
+ (config.shlibdir,
+ config.environment.get(shlibpath_var, '')))
+ config.environment[shlibpath_var] = shlibpath
+ break
+else:
+ lit_config.warning("unable to inject shared library path on '{}'"
+ .format(platform.system()))
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
index 75a38b4c5dad..856fc75c9d74 100644
--- a/test/lit.cfg.py
+++ b/test/lit.cfg.py
@@ -42,6 +42,26 @@ llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
llvm_config.with_system_environment(
["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+ yield "LD_LIBRARY_PATH"
+ elif platform.system() == "Darwin":
+ yield "DYLD_LIBRARY_PATH"
+ elif platform.system() == "Windows":
+ yield "PATH"
+ elif platform.system() == "AIX":
+ yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+ shlibpath = config.llvm_shlib_dir
+ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True)
+ break
+else:
+ lit_config.warning("unable to inject shared library path on '{}'"
+ .format(platform.system()))
# Set up OCAMLPATH to include newly built OCaml libraries.
top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml")
@@ -318,7 +338,7 @@ def have_cxx_shared_library():
try:
readobj_cmd = subprocess.Popen(
- [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE
+ [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE, env=config.environment
)
except OSError:
print("could not exec llvm-readobj")

View File

@ -1,24 +0,0 @@
diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg
index 41e3a589c61e..09f3b17498b0 100644
--- a/tools/polly/test/lit.cfg
+++ b/tools/polly/test/lit.cfg
@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']]
path = os.path.pathsep.join(base_paths + config.extra_paths)
config.environment['PATH'] = path
+# (Copied from polly/test/Unit/lit.cfg)
+if platform.system() == 'Darwin':
+ shlibpath_var = 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+ shlibpath_var = 'PATH'
+else:
+ shlibpath_var = 'LD_LIBRARY_PATH'
+
path = os.path.pathsep.join((config.llvm_libs_dir,
- config.environment.get('LD_LIBRARY_PATH','')))
-config.environment['LD_LIBRARY_PATH'] = path
+ config.environment.get(shlibpath_var,'')))
+config.environment[shlibpath_var] = path
llvm_config.use_default_substitutions()

View File

@ -1,13 +0,0 @@
--- a/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:36:20.550893344 -0700
+++ b/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:37:06.277332960 -0700
@@ -45,8 +45,8 @@
install(TARGETS ${name}
COMPONENT ${name}
EXPORT LLVMExports
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
add_llvm_install_targets(install-${name}
COMPONENT ${name})
endif()

View File

@ -1,137 +0,0 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 471817d68286..c51463304159 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1010,7 +1010,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
install(TARGETS tf_xla_runtime EXPORT LLVMExports
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
# Once we add more modules, we should handle this more automatically.
if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL)
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index 230620c37027..dd16cab1835e 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -876,8 +876,8 @@ macro(add_llvm_library name)
get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella})
install(TARGETS ${name}
${export_to_llvmexports}
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name}
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name})
if (NOT LLVM_ENABLE_IDE)
@@ -2069,7 +2069,7 @@ function(llvm_install_library_symlink name dest type)
set(LLVM_LINK_OR_COPY copy)
endif()
- set(output_dir lib${LLVM_LIBDIR_SUFFIX})
+ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
if(WIN32 AND "${type}" STREQUAL "SHARED")
set(output_dir "${CMAKE_INSTALL_BINDIR}")
endif()
@@ -2344,16 +2344,37 @@ function(llvm_setup_rpath name)
if (APPLE)
set(_install_name_dir INSTALL_NAME_DIR "@rpath")
- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath ${extra_libdir})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS)
# $ORIGIN is not interpreted at link time by aix ld.
# Since BUILD_SHARED_LIBS is only recommended for use by developers,
# hardcode the rpath to build/install lib dir first in this mode.
# FIXME: update this when there is better solution.
- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
elseif(UNIX)
- set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
+ # Note that we add `extra_libdir` (aka `LLVM_LIBRARY_DIR` in our case) back
+ # to `_install_rpath` here.
+ #
+ # In nixpkgs we do not build and install LLVM alongside rdeps of LLVM (i.e.
+ # clang); instead LLVM is its own package and thus lands at its own nix
+ # store path. This makes it so that the default relative rpath (`../lib/`)
+ # does not point at the LLVM shared objects.
+ #
+ # More discussion here:
+ # - https://github.com/NixOS/nixpkgs/pull/235624#discussion_r1220150329
+ # - https://reviews.llvm.org/D146918 (16.0.5+)
+ #
+ # Note that we leave `extra_libdir` in `_build_rpath`: without FHS there is
+ # no potential that this will result in us pulling in the "wrong" LLVM.
+ # Adding this to the build rpath means we aren't forced to use
+ # `installCheckPhase` instead of `checkPhase` (i.e. binaries in the build
+ # dir, pre-install, will have the right rpath for LLVM).
+ #
+ # As noted in the differential above, an alternative solution is to have
+ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set
+ # `CMAKE_INSTALL_RPATH`.
+ set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath ${extra_libdir})
if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-z,origin ")
diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake
index 891c9e6d618c..8d963f3b0069 100644
--- a/cmake/modules/AddOCaml.cmake
+++ b/cmake/modules/AddOCaml.cmake
@@ -147,9 +147,9 @@ function(add_ocaml_library name)
endforeach()
if( APPLE )
- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
elseif( UNIX )
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
endif()
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index d99af79aa38e..21e794224b99 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt
@@ -127,7 +127,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS
)
list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS)
-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}")
+extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}")
set(LLVM_CONFIG_LIBRARY_DIRS
"${LLVM_CONFIG_LIBRARY_DIR}"
# FIXME: Should there be other entries here?
diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
index 370005cd8d7d..7e790bc52111 100644
--- a/tools/llvm-config/BuildVariables.inc.in
+++ b/tools/llvm-config/BuildVariables.inc.in
@@ -23,6 +23,7 @@
#define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@"
#define LLVM_BUILDMODE "@LLVM_BUILDMODE@"
#define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
+#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@"
#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@"
#define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@"
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
index e86eb2b44b10..f63e207e792e 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -366,7 +366,11 @@ int main(int argc, char **argv) {
sys::fs::make_absolute(ActivePrefix, Path);
ActiveBinDir = std::string(Path.str());
}
- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
+ {
+ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX);
+ sys::fs::make_absolute(ActivePrefix, Path);
+ ActiveLibDir = std::string(Path.str());
+ }
{
SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
sys::fs::make_absolute(ActivePrefix, Path);

View File

@ -1,12 +0,0 @@
--- a/utils/lit/lit/TestRunner.py 2024-03-15 17:27:53.170780798 -0700
+++ b/utils/lit/lit/TestRunner.py 2024-03-15 17:28:43.277447791 -0700
@@ -1183,6 +1183,9 @@
f.write("@echo on\n")
f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands))
else:
+ if "DYLD_LIBRARY_PATH" in test.config.environment:
+ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n')
+
for i, ln in enumerate(commands):
match = re.fullmatch(kPdbgRegex, ln)
if match:

View File

@ -1,80 +0,0 @@
diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py
index 81e8dc04acea..479ff95681e2 100644
--- a/test/Unit/lit.cfg.py
+++ b/test/Unit/lit.cfg.py
@@ -3,6 +3,7 @@
# Configuration file for the 'lit' test runner.
import os
+import platform
import subprocess
import lit.formats
@@ -55,3 +56,26 @@ if sys.platform in ["win32", "cygwin"] and os.path.isdir(config.shlibdir):
# Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate.
if sys.platform == "win32" and "SYSTEMDRIVE" in os.environ:
config.environment["SYSTEMDRIVE"] = os.environ["SYSTEMDRIVE"]
+
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+ yield "LD_LIBRARY_PATH"
+ elif platform.system() == "Darwin":
+ yield "DYLD_LIBRARY_PATH"
+ elif platform.system() == "Windows":
+ yield "PATH"
+ elif platform.system() == "AIX":
+ yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+ shlibpath = os.path.pathsep.join(
+ (config.shlibdir,
+ config.environment.get(shlibpath_var, '')))
+ config.environment[shlibpath_var] = shlibpath
+ break
+else:
+ lit_config.warning("unable to inject shared library path on '{}'"
+ .format(platform.system()))
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
index 75a38b4c5dad..856fc75c9d74 100644
--- a/test/lit.cfg.py
+++ b/test/lit.cfg.py
@@ -42,6 +42,26 @@ llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
llvm_config.with_system_environment(
["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+ yield "LD_LIBRARY_PATH"
+ elif platform.system() == "Darwin":
+ yield "DYLD_LIBRARY_PATH"
+ elif platform.system() == "Windows":
+ yield "PATH"
+ elif platform.system() == "AIX":
+ yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+ shlibpath = config.llvm_shlib_dir
+ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True)
+ break
+else:
+ lit_config.warning("unable to inject shared library path on '{}'"
+ .format(platform.system()))
# Set up OCAMLPATH to include newly built OCaml libraries.
top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml")
@@ -318,7 +338,7 @@ def have_cxx_shared_library():
try:
readobj_cmd = subprocess.Popen(
- [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE
+ [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE, env=config.environment
)
except OSError:
print("could not exec llvm-readobj")

View File

@ -1,24 +0,0 @@
diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg
index 41e3a589c61e..09f3b17498b0 100644
--- a/tools/polly/test/lit.cfg
+++ b/tools/polly/test/lit.cfg
@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']]
path = os.path.pathsep.join(base_paths + config.extra_paths)
config.environment['PATH'] = path
+# (Copied from polly/test/Unit/lit.cfg)
+if platform.system() == 'Darwin':
+ shlibpath_var = 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+ shlibpath_var = 'PATH'
+else:
+ shlibpath_var = 'LD_LIBRARY_PATH'
+
path = os.path.pathsep.join((config.llvm_libs_dir,
- config.environment.get('LD_LIBRARY_PATH','')))
-config.environment['LD_LIBRARY_PATH'] = path
+ config.environment.get(shlibpath_var,'')))
+config.environment[shlibpath_var] = path
llvm_config.use_default_substitutions()

View File

@ -82,13 +82,23 @@ let
(if lib.versionAtLeast release_version "19" then ../19/${p} else ../12/${p})
else if
lib.versionAtLeast release_version "18"
&& (p == "clang/purity.patch" || p == "lld/gnu-install-dirs.patch")
&& (
p == "clang/purity.patch"
|| p == "lld/gnu-install-dirs.patch"
|| p == "llvm/gnu-install-dirs.patch"
|| p == "llvm/gnu-install-dirs-polly.patch"
|| p == "llvm/lit-shell-script-runner-set-dyld-library-path.patch"
)
then
../18/${p}
else if
lib.versionAtLeast release_version "15"
&& lib.versionOlder release_version "17"
&& (p == "clang/purity.patch" || p == "libunwind/gnu-install-dirs.patch")
&& (
p == "clang/purity.patch"
|| p == "libunwind/gnu-install-dirs.patch"
|| p == "llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch"
)
then
../15/${p}
else if p == "compiler-rt/X86-support-extension.patch" || p == "lldb/procfs.patch" then
@ -122,6 +132,26 @@ let
../12/${p}
else if lib.versionOlder release_version "14" && p == "lld/gnu-install-dirs.patch" then
../12/${p}
else if
lib.versionAtLeast release_version "14"
&& lib.versionOlder release_version "18"
&& p == "llvm/gnu-install-dirs-polly.patch"
then
../14/${p}
else if
lib.versionAtLeast release_version "16"
&& lib.versionOlder release_version "18"
&& p == "llvm/lit-shell-script-runner-set-dyld-library-path.patch"
then
../16/${p}
else if
lib.versionAtLeast release_version "17" && p == "llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch"
then
../17/${p}
else if
lib.versionAtLeast release_version "15" && p == "llvm/polly-lit-cfg-add-libs-to-dylib-path.patch"
then
../15/${p}
else
"${metadata.versionDir}/${p}";
};

View File

@ -1,13 +0,0 @@
--- a/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:36:20.550893344 -0700
+++ b/tools/polly/cmake/polly_macros.cmake 2024-03-15 17:37:06.277332960 -0700
@@ -45,8 +45,8 @@
install(TARGETS ${name}
COMPONENT ${name}
EXPORT LLVMExports
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
add_llvm_install_targets(install-${name}
COMPONENT ${name})
endif()

View File

@ -1,137 +0,0 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 471817d68286..c51463304159 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1010,7 +1010,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
install(TARGETS tf_xla_runtime EXPORT LLVMExports
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
# Once we add more modules, we should handle this more automatically.
if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL)
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index 230620c37027..dd16cab1835e 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -876,8 +876,8 @@ macro(add_llvm_library name)
get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella})
install(TARGETS ${name}
${export_to_llvmexports}
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name}
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name})
if (NOT LLVM_ENABLE_IDE)
@@ -2069,7 +2069,7 @@ function(llvm_install_library_symlink name dest type)
set(LLVM_LINK_OR_COPY copy)
endif()
- set(output_dir lib${LLVM_LIBDIR_SUFFIX})
+ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
if(WIN32 AND "${type}" STREQUAL "SHARED")
set(output_dir "${CMAKE_INSTALL_BINDIR}")
endif()
@@ -2344,16 +2344,37 @@ function(llvm_setup_rpath name)
if (APPLE)
set(_install_name_dir INSTALL_NAME_DIR "@rpath")
- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath ${extra_libdir})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS)
# $ORIGIN is not interpreted at link time by aix ld.
# Since BUILD_SHARED_LIBS is only recommended for use by developers,
# hardcode the rpath to build/install lib dir first in this mode.
# FIXME: update this when there is better solution.
- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
elseif(UNIX)
- set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
+ # Note that we add `extra_libdir` (aka `LLVM_LIBRARY_DIR` in our case) back
+ # to `_install_rpath` here.
+ #
+ # In nixpkgs we do not build and install LLVM alongside rdeps of LLVM (i.e.
+ # clang); instead LLVM is its own package and thus lands at its own nix
+ # store path. This makes it so that the default relative rpath (`../lib/`)
+ # does not point at the LLVM shared objects.
+ #
+ # More discussion here:
+ # - https://github.com/NixOS/nixpkgs/pull/235624#discussion_r1220150329
+ # - https://reviews.llvm.org/D146918 (16.0.5+)
+ #
+ # Note that we leave `extra_libdir` in `_build_rpath`: without FHS there is
+ # no potential that this will result in us pulling in the "wrong" LLVM.
+ # Adding this to the build rpath means we aren't forced to use
+ # `installCheckPhase` instead of `checkPhase` (i.e. binaries in the build
+ # dir, pre-install, will have the right rpath for LLVM).
+ #
+ # As noted in the differential above, an alternative solution is to have
+ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set
+ # `CMAKE_INSTALL_RPATH`.
+ set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
+ set(_install_rpath ${extra_libdir})
if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-z,origin ")
diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake
index 891c9e6d618c..8d963f3b0069 100644
--- a/cmake/modules/AddOCaml.cmake
+++ b/cmake/modules/AddOCaml.cmake
@@ -147,9 +147,9 @@ function(add_ocaml_library name)
endforeach()
if( APPLE )
- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
elseif( UNIX )
- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
+ set(ocaml_rpath ${LLVM_LIBRARY_DIR})
endif()
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index d99af79aa38e..21e794224b99 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt
@@ -127,7 +127,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS
)
list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS)
-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}")
+extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}")
set(LLVM_CONFIG_LIBRARY_DIRS
"${LLVM_CONFIG_LIBRARY_DIR}"
# FIXME: Should there be other entries here?
diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
index 370005cd8d7d..7e790bc52111 100644
--- a/tools/llvm-config/BuildVariables.inc.in
+++ b/tools/llvm-config/BuildVariables.inc.in
@@ -23,6 +23,7 @@
#define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@"
#define LLVM_BUILDMODE "@LLVM_BUILDMODE@"
#define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
+#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@"
#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@"
#define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@"
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
index e86eb2b44b10..f63e207e792e 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -366,7 +366,11 @@ int main(int argc, char **argv) {
sys::fs::make_absolute(ActivePrefix, Path);
ActiveBinDir = std::string(Path.str());
}
- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
+ {
+ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX);
+ sys::fs::make_absolute(ActivePrefix, Path);
+ ActiveLibDir = std::string(Path.str());
+ }
{
SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
sys::fs::make_absolute(ActivePrefix, Path);

View File

@ -1,12 +0,0 @@
--- a/utils/lit/lit/TestRunner.py 2024-03-15 17:27:53.170780798 -0700
+++ b/utils/lit/lit/TestRunner.py 2024-03-15 17:28:43.277447791 -0700
@@ -1183,6 +1183,9 @@
f.write("@echo on\n")
f.write("\n@if %ERRORLEVEL% NEQ 0 EXIT\n".join(commands))
else:
+ if "DYLD_LIBRARY_PATH" in test.config.environment:
+ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n')
+
for i, ln in enumerate(commands):
match = re.fullmatch(kPdbgRegex, ln)
if match:

View File

@ -1,80 +0,0 @@
diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py
index 81e8dc04acea..479ff95681e2 100644
--- a/test/Unit/lit.cfg.py
+++ b/test/Unit/lit.cfg.py
@@ -3,6 +3,7 @@
# Configuration file for the 'lit' test runner.
import os
+import platform
import subprocess
import lit.formats
@@ -55,3 +56,26 @@ if sys.platform in ["win32", "cygwin"] and os.path.isdir(config.shlibdir):
# Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate.
if sys.platform == "win32" and "SYSTEMDRIVE" in os.environ:
config.environment["SYSTEMDRIVE"] = os.environ["SYSTEMDRIVE"]
+
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+ yield "LD_LIBRARY_PATH"
+ elif platform.system() == "Darwin":
+ yield "DYLD_LIBRARY_PATH"
+ elif platform.system() == "Windows":
+ yield "PATH"
+ elif platform.system() == "AIX":
+ yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+ shlibpath = os.path.pathsep.join(
+ (config.shlibdir,
+ config.environment.get(shlibpath_var, '')))
+ config.environment[shlibpath_var] = shlibpath
+ break
+else:
+ lit_config.warning("unable to inject shared library path on '{}'"
+ .format(platform.system()))
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
index 75a38b4c5dad..856fc75c9d74 100644
--- a/test/lit.cfg.py
+++ b/test/lit.cfg.py
@@ -42,6 +42,26 @@ llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
llvm_config.with_system_environment(
["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+ if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+ yield "LD_LIBRARY_PATH"
+ elif platform.system() == "Darwin":
+ yield "DYLD_LIBRARY_PATH"
+ elif platform.system() == "Windows":
+ yield "PATH"
+ elif platform.system() == "AIX":
+ yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+ shlibpath = config.llvm_shlib_dir
+ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True)
+ break
+else:
+ lit_config.warning("unable to inject shared library path on '{}'"
+ .format(platform.system()))
# Set up OCAMLPATH to include newly built OCaml libraries.
top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml")
@@ -318,7 +338,7 @@ def have_cxx_shared_library():
try:
readobj_cmd = subprocess.Popen(
- [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE
+ [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE, env=config.environment
)
except OSError:
print("could not exec llvm-readobj")

View File

@ -1,24 +0,0 @@
diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg
index 41e3a589c61e..09f3b17498b0 100644
--- a/tools/polly/test/lit.cfg
+++ b/tools/polly/test/lit.cfg
@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']]
path = os.path.pathsep.join(base_paths + config.extra_paths)
config.environment['PATH'] = path
+# (Copied from polly/test/Unit/lit.cfg)
+if platform.system() == 'Darwin':
+ shlibpath_var = 'DYLD_LIBRARY_PATH'
+elif platform.system() == 'Windows':
+ shlibpath_var = 'PATH'
+else:
+ shlibpath_var = 'LD_LIBRARY_PATH'
+
path = os.path.pathsep.join((config.llvm_libs_dir,
- config.environment.get('LD_LIBRARY_PATH','')))
-config.environment['LD_LIBRARY_PATH'] = path
+ config.environment.get(shlibpath_var,'')))
+config.environment[shlibpath_var] = path
llvm_config.use_default_substitutions()