[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-24 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck closed 
https://github.com/llvm/llvm-project/pull/89756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Fraser Cormack via cfe-commits


@@ -88,10 +88,25 @@ function(link_bc)
 ${ARGN}
   )
 
+  set( LINK_INPUT_ARG ${ARG_INPUTS} )
+  if( WIN32 OR CYGWIN )
+# Create a response file in case the number of inputs exceeds command-line
+# character limits on certain platforms.
+file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
+# Turn it into a space-separate list of input files
+list( JOIN ARG_INPUTS " " RSP_INPUT )
+file( WRITE ${RSP_FILE} ${RSP_INPUT} )
+# Ensure that if this file is removed, we re-run CMake
+set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
+  ${RSP_FILE}
+)

frasercrmck wrote:

Interesting, thank you for pointing that out.

I just tried something inspired by that (looking at 
https://github.com/ROCm/ROCm-Device-Libs/blob/amd-stg-open/cmake/OCL.cmake#L129)
 but when I deleted the configured `.rsp` file it wouldn't know how to rebuild 
it. It did reconfigure and rebuild when I deleted the `.rsp.in` file. It might 
be I've done something wrong, but though I like your suggestion I might stick 
with this one as I've verified it can handle being deleted.

https://github.com/llvm/llvm-project/pull/89756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm edited https://github.com/llvm/llvm-project/pull/89756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/89756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Matt Arsenault via cfe-commits


@@ -88,10 +88,25 @@ function(link_bc)
 ${ARGN}
   )
 
+  set( LINK_INPUT_ARG ${ARG_INPUTS} )
+  if( WIN32 OR CYGWIN )
+# Create a response file in case the number of inputs exceeds command-line
+# character limits on certain platforms.
+file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
+# Turn it into a space-separate list of input files
+list( JOIN ARG_INPUTS " " RSP_INPUT )
+file( WRITE ${RSP_FILE} ${RSP_INPUT} )
+# Ensure that if this file is removed, we re-run CMake
+set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
+  ${RSP_FILE}
+)

arsenm wrote:

rocm device-libs seems to achieve this by using configure_file with a temporary 
rsp input file 

https://github.com/llvm/llvm-project/pull/89756
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Use a response file when building on Windows (PR #89756)

2024-04-23 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/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.

>From 640b18bdf3ccd706a509b534d1b8a01b499eddd7 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 23 Apr 2024 13:50:54 +0100
Subject: [PATCH] [libclc] Use a response file when building on Windows

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.
---
 libclc/cmake/modules/AddLibclc.cmake | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index bbedc244a72899..7f4620fa6a21df 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -88,10 +88,25 @@ function(link_bc)
 ${ARGN}
   )
 
+  set( LINK_INPUT_ARG ${ARG_INPUTS} )
+  if( WIN32 OR CYGWIN )
+# Create a response file in case the number of inputs exceeds command-line
+# character limits on certain platforms.
+file( TO_CMAKE_PATH ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.rsp RSP_FILE )
+# Turn it into a space-separate list of input files
+list( JOIN ARG_INPUTS " " RSP_INPUT )
+file( WRITE ${RSP_FILE} ${RSP_INPUT} )
+# Ensure that if this file is removed, we re-run CMake
+set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
+  ${RSP_FILE}
+)
+set( LINK_INPUT_ARG "@${RSP_FILE}" )
+  endif()
+
   add_custom_command(
 OUTPUT ${ARG_TARGET}.bc
-COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${ARG_INPUTS}
-DEPENDS libclc::llvm-link ${ARG_INPUTS}
+COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
+DEPENDS libclc::llvm-link ${ARG_INPUTS} ${RSP_FILE}
   )
 
   add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc )

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits