Skip to content

Commit effb2f1

Browse files
authored
[libclc] Use a response file when building on Windows (#89756)
We've recently seen the libclc llvm-link invocations become so long that they exceed the character limits on certain platforms. Using a 'response file' should solve this by offloading the list of inputs into a separate file, and using special syntax to pass it to llvm-link. Note that neither the response file nor syntax aren't specific to Windows but we restrict it to that platform regardless. We have the option of expanding it to other platforms in the future.
1 parent e400e90 commit effb2f1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,25 @@ function(link_bc)
8888
${ARGN}
8989
)
9090

91+
set( LINK_INPUT_ARG ${ARG_INPUTS} )
92+
if( WIN32 OR CYGWIN )
93+
# Create a response file in case the number of inputs exceeds command-line
94+
# character limits on certain platforms.
95+
file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
96+
# Turn it into a space-separate list of input files
97+
list( JOIN ARG_INPUTS " " RSP_INPUT )
98+
file( WRITE ${RSP_FILE} ${RSP_INPUT} )
99+
# Ensure that if this file is removed, we re-run CMake
100+
set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
101+
${RSP_FILE}
102+
)
103+
set( LINK_INPUT_ARG "@${RSP_FILE}" )
104+
endif()
105+
91106
add_custom_command(
92107
OUTPUT ${ARG_TARGET}.bc
93-
COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${ARG_INPUTS}
94-
DEPENDS libclc::llvm-link ${ARG_INPUTS}
108+
COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
109+
DEPENDS libclc::llvm-link ${ARG_INPUTS} ${RSP_FILE}
95110
)
96111

97112
add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc )

0 commit comments

Comments
 (0)