diff --git a/patches/metal--deps--indium.patch b/patches/metal--deps--indium.patch index dcfff97..72ac69a 100644 --- a/patches/metal--deps--indium.patch +++ b/patches/metal--deps--indium.patch @@ -8629,10 +8629,53 @@ new file mode 100644 + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt -index 8d95863..603dc3d 100644 +index 8d95863..1af3167 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -159,9 +159,33 @@ if (NOT DARLING) +@@ -2,6 +2,41 @@ project(indium) + cmake_minimum_required(VERSION 3.20) + + find_package(Vulkan REQUIRED) ++ ++# Iridium compiles against these LLVM headers and loads the shared libLLVM of the same major at run time, so the LLVM ++# found here needs an llvm-config that reports a shared library. find_package also looks in /llvm/lib/cmake/llvm ++# for every PATH entry, so with /opt/rocm/bin on PATH it picks ROCm's private LLVM ahead of the system one, and a cached ++# LLVM_DIR can name an LLVM that was removed since. Unless LLVM_DIR names a usable LLVM, use the llvm-config on PATH. ++function(indium_llvm_config_works tool result) ++ set(${result} FALSE PARENT_SCOPE) ++ execute_process(COMMAND "${tool}" --link-shared --libnames ++ OUTPUT_VARIABLE libname RESULT_VARIABLE status ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) ++ if (status EQUAL 0 AND libname) ++ set(${result} TRUE PARENT_SCOPE) ++ endif() ++endfunction() ++ ++set(indium_llvm_usable FALSE) ++if (LLVM_DIR) ++ # /lib/cmake/llvm or /lib64/cmake/llvm ++ get_filename_component(indium_llvm_prefix "${LLVM_DIR}/../../.." ABSOLUTE) ++ indium_llvm_config_works("${indium_llvm_prefix}/bin/llvm-config" indium_llvm_usable) ++endif() ++if (NOT indium_llvm_usable) ++ find_program(INDIUM_PATH_LLVM_CONFIG llvm-config) ++ if (INDIUM_PATH_LLVM_CONFIG) ++ indium_llvm_config_works("${INDIUM_PATH_LLVM_CONFIG}" indium_path_llvm_usable) ++ execute_process(COMMAND "${INDIUM_PATH_LLVM_CONFIG}" --cmakedir ++ OUTPUT_VARIABLE indium_path_llvm_dir RESULT_VARIABLE indium_status ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) ++ if (indium_path_llvm_usable AND indium_status EQUAL 0 AND EXISTS "${indium_path_llvm_dir}") ++ if (LLVM_DIR) ++ message(STATUS "LLVM_DIR=${LLVM_DIR} has no llvm-config with a shared library; using ${indium_path_llvm_dir}") ++ endif() ++ set(LLVM_DIR "${indium_path_llvm_dir}" CACHE PATH "The directory containing a CMake configuration file for LLVM." FORCE) ++ endif() ++ endif() ++endif() ++ + find_package(LLVM REQUIRED CONFIG) + + if (DARLING) +@@ -158,11 +193,35 @@ if (NOT DARLING) + ) endif() -execute_process( @@ -8667,10 +8710,11 @@ index 8d95863..603dc3d 100644 +endforeach() +if (NOT HOST_LLVM_LIBNAME) + message(FATAL_ERROR "No working llvm-config for LLVM ${LLVM_VERSION} (LLVM_DIR=${LLVM_DIR}). " -+ "Remove LLVM_DIR from the CMake cache or install the matching LLVM.") ++ "Install an LLVM with a shared libLLVM, or pass -DLLVM_DIR=.") +endif() target_compile_definitions(iridium PRIVATE + "HOST_LLVM_LIBNAME=\"${HOST_LLVM_LIBNAME}\"" diff --git a/src/iridium/dynamic-llvm.cpp b/src/iridium/dynamic-llvm.cpp index 1b5876e..03af560 100644 --- a/src/iridium/dynamic-llvm.cpp