Skip to content

Commit ce03fe4

Browse files
authored
Merge pull request #4071 from etcwilde/ewilde/link-swift-compiler-modules-to-lldb
Link swift compiler modules to lldb
2 parents acc147c + f60ab4a commit ce03fe4

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ add_lldb_library(lldbPluginExpressionParserSwift PLUGIN
4545
Support
4646
Core
4747
)
48+
49+
if(BOOTSTRAPPING_MODE)
50+
target_link_libraries(lldbPluginExpressionParserSwift
51+
PRIVATE
52+
swiftCompilerModules)
53+
else()
54+
target_link_libraries(lldbPluginExpressionParserSwift
55+
PRIVATE
56+
swiftCompilerStub)
57+
endif()

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

@@ -80,6 +81,8 @@ void SwiftLanguage::Initialize() {
8081
lldb_private::formatters::NSArray_Additionals::GetAdditionalSynthetics()
8182
.emplace(g_NSArrayClass1,
8283
lldb_private::formatters::swift::ArraySyntheticFrontEndCreator);
84+
85+
initializeSwiftModules();
8386
}
8487

8588
void SwiftLanguage::Terminate() {

lldb/tools/lldb-test/CMakeLists.txt

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

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

0 commit comments

Comments
 (0)