[llvm] 81b1f47 - [CMake] Serialize `build_native_tool`

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 29 00:54:21 PDT 2023


Author: NAKAMURA Takumi
Date: 2023-04-29T16:53:41+09:00
New Revision: 81b1f4746f8ac6d57307f9c9792bf3cc77d909ae

URL: https://github.com/llvm/llvm-project/commit/81b1f4746f8ac6d57307f9c9792bf3cc77d909ae
DIFF: https://github.com/llvm/llvm-project/commit/81b1f4746f8ac6d57307f9c9792bf3cc77d909ae.diff

LOG: [CMake] Serialize `build_native_tool`

To prevent race in `NATIVE`, let each action depend on preceding action.
At the moment, this is restricted only for "Visual Studio".

For example,

  - `llvm-tblgen-host` depends on the target's `llvm-tblgen`.
  - `clang-tblgen-host` depends on the target's `clang-tblgen` and `llvm-tblgen-host`.

This is rework for D54153.
`build_native_tool` has been introduced since D60024.

Differential Revision: https://reviews.llvm.org/D149072

Added: 
    

Modified: 
    llvm/cmake/modules/CrossCompile.cmake
    llvm/cmake/modules/TableGen.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
index a46a0fd630b0f..7c750f01e0cab 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -112,11 +112,17 @@ function(build_native_tool target output_path_var)
   endif()
   set(output_path ${output_path}${LLVM_HOST_EXECUTABLE_SUFFIX})
 
+  # Make chain of preceding actions
+  if(CMAKE_GENERATOR MATCHES "Visual Studio")
+    get_property(host_targets GLOBAL PROPERTY ${PROJECT_NAME}_HOST_TARGETS)
+    set_property(GLOBAL APPEND PROPERTY ${PROJECT_NAME}_HOST_TARGETS ${output_path})
+  endif()
+
   llvm_ExternalProject_BuildCmd(build_cmd ${target} ${${PROJECT_NAME}_NATIVE_BUILD}
                                 CONFIGURATION Release)
   add_custom_command(OUTPUT "${output_path}"
                      COMMAND ${build_cmd}
-                     DEPENDS CONFIGURE_${PROJECT_NAME}_NATIVE ${ARG_DEPENDS}
+                     DEPENDS CONFIGURE_${PROJECT_NAME}_NATIVE ${ARG_DEPENDS} ${host_targets}
                      WORKING_DIRECTORY "${${PROJECT_NAME}_NATIVE_BUILD}"
                      COMMENT "Building native ${target}..."
                      USES_TERMINAL)

diff  --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
index 70c2edb8c833f..b548dbec95900 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -171,14 +171,6 @@ macro(add_tablegen target project)
       add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE})
       set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE)
 
-      # Create an artificial dependency between tablegen projects, because they
-      # compile the same dependencies, thus using the same build folders.
-      # FIXME: A proper fix requires sequentially chaining tablegens.
-      if (NOT ${project} STREQUAL LLVM AND TARGET ${project}-tablegen-host AND
-          TARGET LLVM-tablegen-host)
-        add_dependencies(${project}-tablegen-host LLVM-tablegen-host)
-      endif()
-
       # If we're using the host tablegen, and utils were not requested, we have no
       # need to build this tablegen.
       if ( NOT LLVM_BUILD_UTILS )


        


More information about the llvm-commits mailing list