Author: Wenju He Date: 2026-03-17T09:45:52+08:00 New Revision: 4abb927bacf37f18f6359a41639a6d1b3bffffb5
URL: https://github.com/llvm/llvm-project/commit/4abb927bacf37f18f6359a41639a6d1b3bffffb5 DIFF: https://github.com/llvm/llvm-project/commit/4abb927bacf37f18f6359a41639a6d1b3bffffb5.diff LOG: [libclc][CMake] Use clang/llvm-ar on Windows (#186726) When LLVM_TARGETS_TO_BUILD contains host target, runtime build sets CMAKE_C_COMPILER to clang-cl on Windows. Changes to fix build on Windows: - libclc struggles to pass specific flags to clang-cl MSVC-like interface. - compile flag handling will be consistent across all host systems. - libclc build is cross-compilation for offloading targets. Added: Modified: libclc/cmake/modules/CMakeCLCInformation.cmake libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake llvm/runtimes/CMakeLists.txt Removed: ################################################################################ diff --git a/libclc/cmake/modules/CMakeCLCInformation.cmake b/libclc/cmake/modules/CMakeCLCInformation.cmake index f92592221f034..3fb67d91dd1e6 100644 --- a/libclc/cmake/modules/CMakeCLCInformation.cmake +++ b/libclc/cmake/modules/CMakeCLCInformation.cmake @@ -11,14 +11,32 @@ if(NOT CMAKE_CLC_COMPILE_OBJECT) "<CMAKE_CLC_COMPILER> -x cl <DEFINES> <INCLUDES> <FLAGS> -c -o <OBJECT> <SOURCE>") endif() +# Finds a required LLVM tool by searching the CLC compiler directory first. +function(find_llvm_tool name out_var) + cmake_path(GET CMAKE_CLC_COMPILER PARENT_PATH llvm_bin_dir) + find_program(${out_var} + NAMES ${name} + HINTS "${llvm_bin_dir}" + DOC "libclc: path to the ${name} tool" + ) + if(NOT ${out_var}) + message(FATAL_ERROR "${name} not found for libclc build.") + endif() +endfunction() + +find_llvm_tool(llvm-ar CLC_AR) +find_llvm_tool(llvm-ranlib CLC_RANLIB) + if(NOT DEFINED CMAKE_CLC_ARCHIVE_CREATE) - set(CMAKE_CLC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_CLC_ARCHIVE_CREATE "${CLC_AR} qc <TARGET> <OBJECTS>") endif() + if(NOT DEFINED CMAKE_CLC_ARCHIVE_APPEND) - set(CMAKE_CLC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>") + set(CMAKE_CLC_ARCHIVE_APPEND "${CLC_AR} q <TARGET> <OBJECTS>") endif() + if(NOT DEFINED CMAKE_CLC_ARCHIVE_FINISH) - set(CMAKE_CLC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") + set(CMAKE_CLC_ARCHIVE_FINISH "${CLC_RANLIB} <TARGET>") endif() set(CMAKE_CLC_USE_LINKER_INFORMATION FALSE) diff --git a/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake b/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake index 2138ad85d0059..0ff60eb1b1144 100644 --- a/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake +++ b/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake @@ -4,7 +4,22 @@ if(NOT CMAKE_CLC_COMPILER) "The CLC language requires the C compiler (CMAKE_C_COMPILER) to be " "Clang, but CMAKE_C_COMPILER_ID is '${CMAKE_C_COMPILER_ID}'.") endif() - set(CMAKE_CLC_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "CLC compiler") + + # Use the regular clang driver if the C compiler is clang-cl. + if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + cmake_path(GET CMAKE_C_COMPILER PARENT_PATH llvm_bin_dir) + find_program(clang_exe clang + HINTS "${llvm_bin_dir}" + NO_DEFAULT_PATH + ) + if(NOT clang_exe) + message(FATAL_ERROR "clang-cl detected, but clang not found in ${llvm_bin_dir}") + endif() + set(clc_compiler "${clang_exe}") + else() + set(clc_compiler "${CMAKE_C_COMPILER}") + endif() + set(CMAKE_CLC_COMPILER "${clc_compiler}" CACHE FILEPATH "libclc: CLC compiler") endif() mark_as_advanced(CMAKE_CLC_COMPILER) diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index fba0c7a01f972..a2ca2aba1f1eb 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -554,7 +554,7 @@ if(build_runtimes) # TODO: We need to consider passing it as '-DRUNTIMES_x86_64_LLVM_ENABLE_RUNTIMES'. if("libclc" IN_LIST LLVM_ENABLE_RUNTIMES) - foreach(dep clang llvm-as llvm-link opt) + foreach(dep clang llvm-as llvm-link opt llvm-ar llvm-ranlib) if(TARGET ${dep}) list(APPEND extra_deps ${dep}) endif() _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
