[llvm] [orc-rt] Add ORC_RT_BEDROCK_LIBRARY_TYPE (STATIC/SHARED) (PR #223288)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 19:32:49 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/223288
Add CMake options to build bedrock as either a static or shared library. Default is static.
This is CMake infrastructure only. Shared library builds aren't actually useable yet: bedrock doesn't export its C++ API, and its C API is insufficient to do anything interesting. Tools and test code are updated to link against the -object libraries directly, since they use the (unexported) C++ API.
>From 9e4e0edbb79e5326dd0db10853f7faaf31fd7e12 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at apple.com>
Date: Mon, 14 Sep 2026 12:08:35 +1000
Subject: [PATCH] [orc-rt] Add ORC_RT_BEDROCK_LIBRARY_TYPE (STATIC/SHARED)
Add CMake options to build bedrock as either a static or shared library.
Default is static.
This is CMake infrastructure only. Shared library builds aren't actually
useable yet: bedrock doesn't export its C++ API, and its C API is
insufficient to do anything interesting. Tools and test code are updated
to link against the -object libraries directly, since they use the
(unexported) C++ API.
---
orc-rt/CMakeLists.txt | 16 ++++++++++++++++
orc-rt/lib/bedrock/CMakeLists.txt | 2 +-
orc-rt/test/tools/CMakeLists.txt | 10 +++++++---
orc-rt/test/unit/CMakeLists.txt | 7 ++++---
orc-rt/tools/ogre/CMakeLists.txt | 5 ++++-
5 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/orc-rt/CMakeLists.txt b/orc-rt/CMakeLists.txt
index 01928f1fbc380..75050fd2802fc 100644
--- a/orc-rt/CMakeLists.txt
+++ b/orc-rt/CMakeLists.txt
@@ -66,6 +66,22 @@ if(NOT ORC_RT_ENABLE_PIC AND
"position-independent.")
endif()
+# --- Bedrock Library Type: SHARED / STATIC ---
+set(orc_rt_bedrock_library_types SHARED STATIC)
+set(ORC_RT_BEDROCK_LIBRARY_TYPE "STATIC" CACHE STRING
+ "Build Bedrock as SHARED or STATIC")
+set_property(CACHE ORC_RT_BEDROCK_LIBRARY_TYPE PROPERTY STRINGS
+ ${orc_rt_bedrock_library_types})
+string(TOUPPER "${ORC_RT_BEDROCK_LIBRARY_TYPE}" ORC_RT_BEDROCK_LIBRARY_TYPE)
+if(NOT ORC_RT_BEDROCK_LIBRARY_TYPE IN_LIST orc_rt_bedrock_library_types)
+ message(FATAL_ERROR "ORC_RT_BEDROCK_LIBRARY_TYPE must be one of: "
+ "${orc_rt_bedrock_library_types}")
+endif()
+if(ORC_RT_BEDROCK_LIBRARY_TYPE STREQUAL "SHARED" AND NOT ORC_RT_ENABLE_PIC)
+ message(WARNING
+ "ORC_RT_BEDROCK_LIBRARY_TYPE is SHARED, but ORC_RT_ENABLE_PIC is OFF.")
+endif()
+
# --- Language runtime (RTTI / exceptions) ---
option(ORC_RT_ENABLE_RTTI "Enable RTTI." ON)
option(ORC_RT_ENABLE_EXCEPTIONS "Enable exceptions." ON)
diff --git a/orc-rt/lib/bedrock/CMakeLists.txt b/orc-rt/lib/bedrock/CMakeLists.txt
index 640210a4d1ff1..0b18e99c134bd 100644
--- a/orc-rt/lib/bedrock/CMakeLists.txt
+++ b/orc-rt/lib/bedrock/CMakeLists.txt
@@ -90,7 +90,7 @@ target_compile_options(orc-rt-bedrock-objects PRIVATE ${ORC_RT_COMPILE_FLAGS})
# The shipped library: Bedrock's objects plus Support's (Support is never
# shipped on its own).
-add_library(orc-rt-bedrock STATIC)
+add_library(orc-rt-bedrock ${ORC_RT_BEDROCK_LIBRARY_TYPE})
target_link_libraries(orc-rt-bedrock PUBLIC orc-rt-headers)
diff --git a/orc-rt/test/tools/CMakeLists.txt b/orc-rt/test/tools/CMakeLists.txt
index 0b4ccca9b6453..f34394d463a54 100644
--- a/orc-rt/test/tools/CMakeLists.txt
+++ b/orc-rt/test/tools/CMakeLists.txt
@@ -4,12 +4,16 @@
# --- smoke-check test tool ---
add_executable(orc-rt-smoke-check orc-rt-smoke-check.cpp)
+# These use the C++ API, which orc-rt-bedrock does not export when built as a
+# shared library, so they link the objects rather than the shipped library.
+
# -- logging-check test tool ---
add_executable(orc-rt-log-check orc-rt-log-check.cpp)
target_compile_options(orc-rt-log-check PRIVATE ${ORC_RT_COMPILE_FLAGS})
-target_link_libraries(orc-rt-log-check PRIVATE orc-rt-bedrock)
-
+target_link_libraries(orc-rt-log-check
+ PRIVATE orc-rt-bedrock-objects orc-rt-support-objects)
add_executable(orc-rt-process-info-check orc-rt-process-info-check.cpp)
target_compile_options(orc-rt-process-info-check PRIVATE ${ORC_RT_COMPILE_FLAGS})
-target_link_libraries(orc-rt-process-info-check PRIVATE orc-rt-bedrock)
+target_link_libraries(orc-rt-process-info-check
+ PRIVATE orc-rt-bedrock-objects orc-rt-support-objects)
diff --git a/orc-rt/test/unit/CMakeLists.txt b/orc-rt/test/unit/CMakeLists.txt
index bfcca8df3a385..ca8ea5faddd18 100644
--- a/orc-rt/test/unit/CMakeLists.txt
+++ b/orc-rt/test/unit/CMakeLists.txt
@@ -103,8 +103,8 @@ target_compile_definitions(BedrockTests PRIVATE
"NDM_TEST_LIB_PATH=\"$<TARGET_FILE:NativeDylibManagerTestLib>\"")
add_dependencies(BedrockTests NativeDylibManagerTestLib)
-# Build a shared library for RTTICrossDylibTest. It links its own copy of
-# orc-rt-bedrock, giving it a LibraryID distinct from SupportTests's, so the
+# Build a shared library for RTTICrossDylibTest. It links its own copy of the
+# runtime objects, giving it a LibraryID distinct from SupportTests's, so the
# test exercises RTTI identity across a real library boundary rather than
# simulating one within a single binary. SupportTests links it directly, the
# same way any other consumer of orc-rt would.
@@ -114,5 +114,6 @@ set_target_properties(RTTICrossDylibTestLib PROPERTIES
PREFIX ""
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON)
-target_link_libraries(RTTICrossDylibTestLib PRIVATE orc-rt-bedrock)
+target_link_libraries(RTTICrossDylibTestLib
+ PRIVATE orc-rt-bedrock-objects orc-rt-support-objects)
target_link_libraries(SupportTests PRIVATE RTTICrossDylibTestLib)
diff --git a/orc-rt/tools/ogre/CMakeLists.txt b/orc-rt/tools/ogre/CMakeLists.txt
index 0a04175ed6dd3..a448a7f1b76bf 100644
--- a/orc-rt/tools/ogre/CMakeLists.txt
+++ b/orc-rt/tools/ogre/CMakeLists.txt
@@ -1,3 +1,6 @@
add_executable(ogre ogre.cpp)
target_compile_options(ogre PRIVATE ${ORC_RT_COMPILE_FLAGS})
-target_link_libraries(ogre PRIVATE orc-rt-bedrock)
+# ogre uses the C++ API, which orc-rt-bedrock does not export when built as a
+# shared library, so link the objects rather than the shipped library.
+target_link_libraries(ogre
+ PRIVATE orc-rt-bedrock-objects orc-rt-support-objects)
More information about the llvm-commits
mailing list