[llvm] [cmake] Serialize native builds for Make generator (PR #121021)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 25 02:55:38 PST 2024
https://github.com/arthurqiu updated https://github.com/llvm/llvm-project/pull/121021
>From d3c3711e2ac030a2edc9c8a49b4c6c213615763a 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] FileLock.cmake to serialize sub-make build for native targets
---
llvm/cmake/modules/FileLock.cmake | 9 +++++++++
llvm/cmake/modules/LLVMExternalProjectUtils.cmake | 6 +++++-
2 files changed, 14 insertions(+), 1 deletion(-)
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..0ee40a68333f2a
--- /dev/null
+++ b/llvm/cmake/modules/FileLock.cmake
@@ -0,0 +1,9 @@
+# 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})
+separate_arguments(command_args NATIVE_COMMAND "${COMMAND}")
+execute_process(COMMAND ${command_args} COMMAND_ERROR_IS_FATAL ANY)
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 "")
More information about the llvm-commits
mailing list