CHIP-SPV / chipStar

chipStar is a tool for compiling and running HIP/CUDA on SPIR-V via OpenCL or Level Zero APIs.
Other
225 stars 33 forks source link

fails to build when `/usr/bin/clang` doesn't exist #705

Closed franz closed 11 months ago

franz commented 11 months ago

When trying to build with clang-17 installed from apt.llvm.org, the build fails with an error message about an unknown command /usr/bin/clang. CMake was invoked with -DLLVM_CONFIG_BIN=/usr/bin/llvm-config-17. The code in cmake/FindLLVM.cmake correctly finds the clang binary at /usr/lib/llvm-17/bin/clang, however the code in bitcode/ROCm-Device-Libs/cmake/OCL.cmake tries to use ${LLVM_CONFIG_DIR}/clang as clang command, which resolves to /usr/bin/clang which does not exist on this system (and even if it did, might not point to version 17).

franz commented 11 months ago
diff --git a/cmake/OCL.cmake b/cmake/OCL.cmake
index 1c16782..2eaf44e 100644
--- a/cmake/OCL.cmake
+++ b/cmake/OCL.cmake
@@ -99,7 +99,7 @@ macro(opencl_bc_lib)
     if (fext STREQUAL ".cl")
       set(output "${CMAKE_CURRENT_BINARY_DIR}/${fname_we}${BC_EXT}")
       add_custom_command(OUTPUT "${output}"
-        COMMAND ${LLVM_CONFIG_DIR}/clang ${inc_options} ${CLANG_OCL_FLAGS}
+        COMMAND ${CLANG_ROOT_PATH_BIN}/clang ${inc_options} ${CLANG_OCL_FLAGS}
           -emit-llvm -Xclang -mlink-builtin-bitcode -Xclang "${irif_lib_output}"
           -c "${file}" -o "${output}"
         DEPENDS "${file}" "${irif_lib_output}" "${CLANG}"
@@ -130,12 +130,12 @@ macro(opencl_bc_lib)

   add_custom_command(OUTPUT ${OUTPUT_BC_LIB}
     # Link regular library dependencies
-    COMMAND ${LLVM_CONFIG_DIR}/llvm-link
+    COMMAND ${CLANG_ROOT_PATH_BIN}/llvm-link
       -o "${OUT_NAME}.link0${LIB_SUFFIX}" "@${OUT_NAME}_response"
     # Extra link step with internalize
-    COMMAND ${LLVM_CONFIG_DIR}/llvm-link -internalize -only-needed "${name}.link0${LIB_SUFFIX}"
+    COMMAND ${CLANG_ROOT_PATH_BIN}/llvm-link -internalize -only-needed "${name}.link0${LIB_SUFFIX}"
       -o "${OUT_NAME}${LIB_SUFFIX}" ${internal_link_libs}
-    COMMAND ${LLVM_CONFIG_DIR}/opt -passes=strip
+    COMMAND ${CLANG_ROOT_PATH_BIN}/opt -passes=strip
       -o "${OUT_NAME}${STRIP_SUFFIX}" "${OUT_NAME}${LIB_SUFFIX}"
     COMMAND "${PREPARE_BUILTINS}"
       -o ${OUTPUT_BC_LIB} "${OUT_NAME}${STRIP_SUFFIX}"

proposed fix