Skip to content

[libclc] More cross compilation fixes #97811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ add_clang_tool(clang
GENERATE_DRIVER
)

setup_host_tool(clang CLANG clang_exe clang_target)

clang_target_link_libraries(clang
PRIVATE
clangBasic
Expand Down
30 changes: 16 additions & 14 deletions libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ else()
endif()

if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
setup_host_tool( clang CLANG clang_exe clang_target )
setup_host_tool( llvm-as LLVM_AS llvm-as_exe llvm-as_target )
setup_host_tool( llvm-link LLVM_LINK llvm-link_exe llvm-link_target )
setup_host_tool( opt OPT opt_exe opt_target )
get_host_tool_path( clang CLANG clang_exe clang_target )
get_host_tool_path( llvm-as LLVM_AS llvm-as_exe llvm-as_target )
get_host_tool_path( llvm-link LLVM_LINK llvm-link_exe llvm-link_target )
get_host_tool_path( opt OPT opt_exe opt_target )
endif()
endif()

Expand All @@ -97,17 +97,19 @@ if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
endif()

foreach( tool IN ITEMS clang opt llvm-as llvm-link )
if( NOT EXISTS "${${tool}_exe}" AND NOT TARGET "${${tool}_target}" )
if( NOT EXISTS "${${tool}_exe}" AND "${tool}_target" STREQUAL "" )
message( FATAL_ERROR "libclc toolchain incomplete - missing tool ${tool}!" )
endif()
endforeach()

# llvm-spirv is an optional dependency, used to build spirv-* targets.
find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )

if( LLVM_SPIRV )
add_executable( libclc::llvm-spirv IMPORTED GLOBAL )
set_target_properties( libclc::llvm-spirv PROPERTIES IMPORTED_LOCATION ${LLVM_SPIRV} )
# It may be provided in-tree or externally.
if( TARGET llvm-spirv )
get_host_tool_path( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target )
else()
find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
set( llvm-spirv_exe "${LLVM_SPIRV}" )
set( llvm-spirv_target )
endif()

# List of all targets. Note that some are added dynamically below.
Expand All @@ -130,7 +132,7 @@ endif()

# spirv-mesa3d and spirv64-mesa3d targets can only be built with the (optional)
# llvm-spirv external tool.
if( TARGET libclc::llvm-spirv )
if( llvm-spirv_exe )
list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- )
endif()

Expand All @@ -143,7 +145,7 @@ list( SORT LIBCLC_TARGETS_TO_BUILD )
# Verify that the user hasn't requested mesa3d targets without an available
# llvm-spirv tool.
if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD )
if( NOT TARGET libclc::llvm-spirv )
if( NOT llvm-spirv_exe )
message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not installed" )
endif()
endif()
Expand Down Expand Up @@ -401,8 +403,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
set( spv_suffix ${arch_suffix}.spv )
add_custom_command( OUTPUT ${spv_suffix}
COMMAND libclc::llvm-spirv ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
DEPENDS ${builtins_link_lib} ${builtins_link_lib_tgt}
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
)
add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}
Expand Down
2 changes: 2 additions & 0 deletions llvm/tools/llvm-as/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ add_llvm_tool(llvm-as
DEPENDS
intrinsics_gen
)

setup_host_tool(llvm-as LLVM_AS llvm_as_exe llvm_as_target)
2 changes: 2 additions & 0 deletions llvm/tools/llvm-link/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ add_llvm_tool(llvm-link
DEPENDS
intrinsics_gen
)

setup_host_tool(llvm-link LLVM_LINK llvm_link_exe llvm_link_target)
2 changes: 2 additions & 0 deletions llvm/tools/opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ add_llvm_tool(opt
)
target_link_libraries(opt PRIVATE LLVMOptDriver)

setup_host_tool(opt OPT opt_exe opt_target)

export_executable_symbols_for_plugins(opt)
Loading