[llvm] [cmake] Fix overlapping native llvm-min-tblgen builds (PR #121021)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 24 21:35:30 PST 2024


https://github.com/arthurqiu updated https://github.com/llvm/llvm-project/pull/121021

>From 67ae3344ff80708a299375f909b87b447650178a Mon Sep 17 00:00:00 2001
From: Arthurq Qiu <arthurq at nvidia.com>
Date: Mon, 23 Dec 2024 18:09:31 -0800
Subject: [PATCH 1/2] fix parallel build of native llvm-min-tblgen

---
 llvm/tools/llvm-config/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-config/CMakeLists.txt b/llvm/tools/llvm-config/CMakeLists.txt
index 02c2532dba77a7..f233b574297da0 100644
--- a/llvm/tools/llvm-config/CMakeLists.txt
+++ b/llvm/tools/llvm-config/CMakeLists.txt
@@ -101,7 +101,7 @@ if(CMAKE_CROSSCOMPILING)
   endif()
 
   if (NOT LLVM_CONFIG_PATH)
-    build_native_tool(llvm-config LLVM_CONFIG_PATH)
+    build_native_tool(llvm-config LLVM_CONFIG_PATH DEPENDS ${LLVM_TABLEGEN_TARGET} ${LLVM_TABLEGEN_EXE})
     set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
 
     add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})

>From b0dc686e47304d0a4adb33ca3ae9e6e0ce694cbe Mon Sep 17 00:00:00 2001
From: Arthurq Qiu <arthurq at nvidia.com>
Date: Tue, 24 Dec 2024 21:34:16 -0800
Subject: [PATCH 2/2] FileLock.cmake to serialize sub-make build for native
 targets

---
 llvm/cmake/modules/FileLock.cmake                 | 8 ++++++++
 llvm/cmake/modules/LLVMExternalProjectUtils.cmake | 6 +++++-
 llvm/tools/llvm-config/CMakeLists.txt             | 2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 llvm/cmake/modules/FileLock.cmake

diff --git a/llvm/cmake/modules/FileLock.cmake b/llvm/cmake/modules/FileLock.cmake
new file mode 100644
index 00000000000000..63854d3b5cb935
--- /dev/null
+++ b/llvm/cmake/modules/FileLock.cmake
@@ -0,0 +1,8 @@
+# CMake script that synchronizes process execution on a given file lock.
+#
+# Input variables:
+#   LOCK_FILE_PATH    - The file to be locked for the scope of the process of this cmake script.
+#   COMMAND           - The command to be executed.
+
+file(LOCK ${LOCK_FILE_PATH})
+execute_process(COMMAND ${COMMAND})
diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index f7e1165bc4b947..3e843f178f6af5 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -9,7 +9,11 @@ function(llvm_ExternalProject_BuildCmd out_var target bin_dir)
   endif()
   if (CMAKE_GENERATOR MATCHES "Make")
     # Use special command for Makefiles to support parallelism.
-    set(${out_var} "$(MAKE)" "-C" "${bin_dir}" "${target}" PARENT_SCOPE)
+    set(make_cmd "$(MAKE)" "-C" "${bin_dir}" "${target}")
+    set(file_lock_script "${LLVM_CMAKE_DIR}/FileLock.cmake")
+    set(${out_var} ${CMAKE_COMMAND} "-DLOCK_FILE_PATH=${bin_dir}/cmake.lock"
+                                    "-DCOMMAND='${make_cmd}'"
+                                    -P "${file_lock_script}" PARENT_SCOPE)
   else()
     set(tool_args "${LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS}")
     if(NOT tool_args STREQUAL "")
diff --git a/llvm/tools/llvm-config/CMakeLists.txt b/llvm/tools/llvm-config/CMakeLists.txt
index f233b574297da0..02c2532dba77a7 100644
--- a/llvm/tools/llvm-config/CMakeLists.txt
+++ b/llvm/tools/llvm-config/CMakeLists.txt
@@ -101,7 +101,7 @@ if(CMAKE_CROSSCOMPILING)
   endif()
 
   if (NOT LLVM_CONFIG_PATH)
-    build_native_tool(llvm-config LLVM_CONFIG_PATH DEPENDS ${LLVM_TABLEGEN_TARGET} ${LLVM_TABLEGEN_EXE})
+    build_native_tool(llvm-config LLVM_CONFIG_PATH)
     set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
 
     add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})



More information about the llvm-commits mailing list