[libcxx-commits] [PATCH] D158762: [runtimes] Add the ability to include out of tree runtimes

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 24 11:40:56 PDT 2023


ldionne created this revision.
ldionne added a reviewer: phosek.
Herald added a project: All.
ldionne requested review of this revision.
Herald added projects: libc++, libc++abi, libunwind, LLVM.
Herald added subscribers: llvm-commits, libcxx-commits.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.
Herald added a reviewer: libunwind.

LLVM_EXTERNAL_RUNTIMES is similar to LLVM_EXTERNAL_PROJECTS: the
source directory for the external runtime is resolved through the
LLVM_EXTERNAL_<proj>_SOURCE_DIR variable.

This makes it easier to experiment with additional runtimes locally
and provides a relatively low maintenance hook for downstreams to
add their own runtimes outside of the LLVM tree.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158762

Files:
  llvm/docs/CMake.rst
  llvm/runtimes/CMakeLists.txt
  runtimes/CMakeLists.txt


Index: runtimes/CMakeLists.txt
===================================================================
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -41,6 +41,17 @@
   set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
 endforeach()
 
+foreach(proj ${LLVM_EXTERNAL_RUNTIMES})
+  string(TOUPPER "${proj}" canon_name)
+  STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
+  set(proj_dir "${LLVM_EXTERNAL_${canon_name}_SOURCE_DIR}")
+  if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
+    list(APPEND runtimes ${proj_dir})
+  else()
+    message(FATAL_ERROR "LLVM_EXTERNAL_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
+  endif()
+endforeach()
+
 function(runtime_register_component name)
   set_property(GLOBAL APPEND PROPERTY SUB_COMPONENTS ${name})
 endfunction()
Index: llvm/runtimes/CMakeLists.txt
===================================================================
--- llvm/runtimes/CMakeLists.txt
+++ llvm/runtimes/CMakeLists.txt
@@ -15,6 +15,19 @@
   STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
   set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
 endforeach()
+if(LLVM_EXTERNAL_RUNTIMES)
+  string(REPLACE ";" "|" LLVM_EXTERNAL_RUNTIMES_PASSTHROUGH "${LLVM_EXTERNAL_RUNTIMES}")
+  list(APPEND EXTERNAL_RUNTIMES_CMAKE_ARGS -DLLVM_EXTERNAL_RUNTIMES=${LLVM_EXTERNAL_RUNTIMES_PASSTHROUGH})
+endif()
+foreach(proj ${LLVM_EXTERNAL_RUNTIMES})
+  string(TOUPPER "${proj}" canon_name)
+  STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
+  set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR
+    "${LLVM_EXTERNAL_${canon_name}_SOURCE_DIR}"
+    CACHE PATH "Path to ${proj} source directory")
+  list(APPEND EXTERNAL_RUNTIMES_CMAKE_ARGS
+    "-DLLVM_EXTERNAL_${canon_name}_SOURCE_DIR=${LLVM_EXTERNAL_${canon_name}_SOURCE_DIR}")
+endforeach()
 
 function(get_compiler_rt_path path)
   foreach(entry ${runtimes})
@@ -240,6 +253,7 @@
                                       -DCMAKE_CXX_COMPILER_WORKS=ON
                                       -DCMAKE_ASM_COMPILER_WORKS=ON
                                       ${COMMON_CMAKE_ARGS}
+                                      ${EXTERNAL_RUNTIMES_CMAKE_ARGS}
                                       ${RUNTIMES_CMAKE_ARGS}
                                       ${ARG_CMAKE_ARGS}
                            PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
@@ -348,6 +362,7 @@
                                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
                                       -DLLVM_RUNTIMES_TARGET=${name}
                                       ${COMMON_CMAKE_ARGS}
+                                      ${EXTERNAL_RUNTIMES_CMAKE_ARGS}
                                       ${${name}_extra_args}
                            EXTRA_TARGETS ${${name}_extra_targets}
                                          ${${name}_test_targets}
Index: llvm/docs/CMake.rst
===================================================================
--- llvm/docs/CMake.rst
+++ llvm/docs/CMake.rst
@@ -625,6 +625,14 @@
   -DLLVM_EXTERNAL_FOO_SOURCE_DIR=/src/foo
   -DLLVM_EXTERNAL_BAR_SOURCE_DIR=/src/bar``.
 
+**LLVM_EXTERNAL_RUNTIMES**:STRING
+  Semicolon-separated list of additional external runtimes to build. For each
+  additional runtime LLVM_EXTERNAL_<NAME>_SOURCE_DIR has to be specified with
+  the path for the source code of the project. Example:
+  ``-DLLVM_EXTERNAL_RUNTIMES="mylib1;mylib2"
+  -DLLVM_EXTERNAL_MYLIB1_SOURCE_DIR=/src/mylib1
+  -DLLVM_EXTERNAL_MYLIB2_SOURCE_DIR=/src/mylib2``.
+
 **LLVM_EXTERNALIZE_DEBUGINFO**:BOOL
   Generate dSYM files and strip executables and libraries (Darwin Only).
   Defaults to OFF.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158762.553215.patch
Type: text/x-patch
Size: 3695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230824/2887d505/attachment-0001.bin>


More information about the libcxx-commits mailing list