[PATCH] D99620: [CMake][Compiler-rt] Fix `LLVM_MAIN_SRC_DIR` to be correct when `llvm-config` reports a path that doesn't exist.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 30 14:31:17 PDT 2021


delcypher created this revision.
delcypher added a reviewer: llvm-commits.
Herald added subscribers: mgorny, dberris.
delcypher requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

When doing a standalone compiler-rt build we currently rely on
getting information from the `llvm-config` binary. Previously
we would rely on calling `llvm-config --src-root` to find the
LLVM sources. Unfortunately the returned path could easily be wrong
if the sources were built on another machine.

Now that compiler-rt is part of a monorepo we can easily fix this
problem by finding the LLVM source tree next to `compiler-rt` in
the monorepo.

To avoid anyone breaking anyone who relies on the current behavior
relying the monorepo layout only happens if the path reported by
`llvm-config --src-root` doesn't exist.

rdar://76016632


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99620

Files:
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake


Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===================================================================
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -240,6 +240,21 @@
     set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
     set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Paths to LLVM headers")
 
+    # `--src-root` might report a path does not exist (e.g. built on another machine).
+    # In this case we fallback on the LLVM sources living next to `compiler-rt` which
+    # is true in the compiler-rt is checked out as part of the monorepo.
+    if (NOT EXISTS "${LLVM_MAIN_SRC_DIR}")
+      # TODO(dliew): We should make this behavior the only behavior rather than
+      # a fallback once we know nobody relies on the old behavior.
+      message(WARNING "LLVM source directory (${LLVM_MAIN_SRC_DIR}) reported by llvm-config does not exist")
+      get_filename_component(LLVM_MAIN_SRC_DIR_REL "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" ABSOLUTE)
+      if (NOT EXISTS "${LLVM_MAIN_SRC_DIR_REL}")
+        message(FATAL_ERROR "LLVM source directory (${LLVM_MAIN_SRC_DIR_REL}) does not exist")
+      endif()
+      set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_REL}")
+    endif()
+    message(STATUS "LLVM source directory: \"${LLVM_MAIN_SRC_DIR}\"")
+
     # Detect if we have the LLVMXRay and TestingSupport library installed and
     # available from llvm-config.
     execute_process(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99620.334271.patch
Type: text/x-patch
Size: 1501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210330/89ef3b55/attachment.bin>


More information about the llvm-commits mailing list