Skip to content

Commit 56da298

Browse files
committed
lldb: link the swift compiler's swift modules to lldb
This is needed for the swift expression parser once parts of the parser are implemented in swift.
1 parent b661a19 commit 56da298

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

lldb/cmake/modules/AddLLDB.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,40 @@ function(add_lldb_library name)
151151
endif()
152152
endfunction(add_lldb_library)
153153

154+
# BEGIN Swift Mods
155+
function(add_properties_for_swift_modules target)
156+
if (BOOTSTRAPPING_MODE)
157+
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
158+
if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|.*HOSTLIBS")
159+
target_link_directories(${target} PRIVATE
160+
"${CMAKE_OSX_SYSROOT}/usr/lib/swift"
161+
"${LLDB_SWIFT_LIBS}/macosx")
162+
set_property(TARGET ${target} APPEND PROPERTY INSTALL_RPATH
163+
"/usr/lib/swift")
164+
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
165+
target_link_directories(${target} PRIVATE "${LLDB_SWIFT_LIBS}/macosx")
166+
set_property(TARGET ${target} APPEND PROPERTY INSTALL_RPATH
167+
"${LLDB_SWIFT_LIBS}/macosx")
168+
else()
169+
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${BOOTSTRAPPING_MODE}'")
170+
endif()
171+
172+
# Workaround for a linker crash related to autolinking: rdar://77839981
173+
set_property(TARGET ${target} APPEND_STRING PROPERTY
174+
LINK_FLAGS " -lobjc ")
175+
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
176+
string(REGEX MATCH "^[^-]*" arch ${TARGET_TRIPLE})
177+
target_link_libraries(${target} PRIVATE swiftCore-linux-${arch})
178+
179+
# TODO: add "${LLDB_SWIFT_LIBS}/linux" to BUILD_RPATH and not INSTALL_RPATH.
180+
# This does not work for some reason.
181+
set_property(TARGET ${target} APPEND PROPERTY INSTALL_RPATH
182+
"${LLDB_SWIFT_LIBS}/linux;$ORIGIN/../lib/swift/linux")
183+
endif()
184+
endif()
185+
endfunction()
186+
# END Swift Mods
187+
154188
function(add_lldb_executable name)
155189
cmake_parse_arguments(ARG
156190
"GENERATE_INSTALL"

lldb/source/API/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ add_lldb_library(liblldb SHARED ${option_framework}
125125
${option_install_prefix}
126126
)
127127

128+
# BEGIN Swift Mods
129+
add_properties_for_swift_modules(liblldb)
130+
# END Swift Mods
131+
128132
# lib/pythonX.Y/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
129133
# which depends on lib/libLLVM*.so (BUILD_SHARED_LIBS) or lib/libLLVM-10git.so
130134
# (LLVM_LINK_LLVM_DYLIB). Add an additional rpath $ORIGIN/../../../../lib so

lldb/source/Plugins/ExpressionParser/Swift/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_lldb_library(lldbPluginExpressionParserSwift PLUGIN
3737
swiftSIL
3838
swiftSILOptimizer
3939
swiftSerialization
40+
swiftCompilerModules
4041
clangAST
4142
clangBasic
4243
clangRewrite

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "swift/AST/Module.h"
4040
#include "swift/AST/Type.h"
4141
#include "swift/AST/Types.h"
42+
#include "swift/Basic/InitializeSwiftModules.h"
4243
#include "swift/Demangling/ManglingMacros.h"
4344
#include "llvm/Support/ConvertUTF.h"
4445

@@ -79,6 +80,8 @@ void SwiftLanguage::Initialize() {
7980
lldb_private::formatters::NSArray_Additionals::GetAdditionalSynthetics()
8081
.emplace(g_NSArrayClass1,
8182
lldb_private::formatters::swift::ArraySyntheticFrontEndCreator);
83+
84+
initializeSwiftModules();
8285
}
8386

8487
void SwiftLanguage::Terminate() {

lldb/tools/lldb-test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ add_lldb_tool(lldb-test
2424
Support
2525
)
2626

27+
# BEGIN Swift Mods
28+
add_properties_for_swift_modules(lldb-test)
29+
# END Swift Mods
30+
2731
if(Python3_RPATH)
2832
set_property(TARGET lldb-test APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
2933
set_property(TARGET lldb-test APPEND PROPERTY BUILD_RPATH "${Python3_RPATH}")

0 commit comments

Comments
 (0)