Skip to content

[LLDB] Support building LLDB standalone without Swift #6532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions lldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ endif()
# Must go below project(..)
include(GNUInstallDirs)

# BEGIN SWIFT MOD
option(LLDB_ENABLE_SWIFT_SUPPORT "Enable swift support" ON)
# END SWIFT MOD

if(LLDB_BUILT_STANDALONE)
include(LLDBStandalone)

Expand All @@ -33,25 +37,29 @@ include(LLDBConfig)
include(AddLLDB)

# BEGIN - Swift Mods
if(EXISTS "${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}")
list(APPEND CMAKE_MODULE_PATH
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake"
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake/modules")
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../swift)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake/modules")
if (LLDB_ENABLE_SWIFT_SUPPORT)
if(EXISTS "${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}")
list(APPEND CMAKE_MODULE_PATH
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake"
"${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/cmake/modules")
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../swift)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake/modules")
endif()
endif()

# When we have the early SwiftSyntax build, we can include its parser.
if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
set(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS
${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
if(NOT EXISTS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS}")
message(STATUS "Skipping Swift Swift parser integration due to missing early SwiftSyntax")
else()
set(SWIFT_SWIFT_PARSER TRUE)
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS})
if (LLDB_ENABLE_SWIFT_SUPPORT)
if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
set(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS
${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
if(NOT EXISTS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS}")
message(STATUS "Skipping Swift Swift parser integration due to missing early SwiftSyntax")
else()
set(SWIFT_SWIFT_PARSER TRUE)
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS})
endif()
endif()
endif()
# END - Swift Mods
Expand Down
32 changes: 21 additions & 11 deletions lldb/cmake/modules/LLDBConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ option(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
"Fail to configure if certain requirements are not met for testing." OFF)

# BEGIN SWIFT MOD
option(LLDB_ENABLE_SWIFT_SUPPORT "Enable swift support" ON)
option(LLDB_ENABLE_WERROR "Fail and stop if a warning is triggered." ${LLVM_ENABLE_WERROR})
if(LLDB_ENABLE_SWIFT_SUPPORT)
add_definitions( -DLLDB_ENABLE_SWIFT )
else()
# LLVM_DISTRIBUTION_COMPONENTS may have swift-specific things in them (e.g.
# repl_swift). This may be set in a cache where LLDB_ENABLE_SWIFT_SUPPORT does
# not yet have a value. We have to touch up LLVM_DISTRIBUTION_COMPONENTS after
# the fact.
if(LLVM_DISTRIBUTION_COMPONENTS)
list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS repl_swift)
set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE)
endif()
endif()
# END SWIFT CODE

Expand Down Expand Up @@ -210,17 +218,19 @@ else ()
endif ()
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")

if(NOT LLDB_BUILT_STANDALONE)
if (LLVM_EXTERNAL_SWIFT_SOURCE_DIR)
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/include)
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims)
if(LLDB_ENABLE_SWIFT_SUPPORT)
if(NOT LLDB_BUILT_STANDALONE)
if (LLVM_EXTERNAL_SWIFT_SOURCE_DIR)
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/include)
include_directories(${LLVM_EXTERNAL_SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims)
else ()
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/include)
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/stdlib/public/SwiftShims)
endif ()
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../swift/include")
else ()
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/include)
include_directories(${CMAKE_SOURCE_DIR}/tools/swift/stdlib/public/SwiftShims)
endif ()
include_directories("${CMAKE_CURRENT_BINARY_DIR}/../swift/include")
else ()
include_directories("${SWIFT_INCLUDE_DIRS}")
include_directories("${SWIFT_INCLUDE_DIRS}")
endif()
endif()

# GCC silently accepts any -Wno-<foo> option, but warns about those options
Expand Down
15 changes: 11 additions & 4 deletions lldb/cmake/modules/LLDBStandalone.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install

find_package(LLVM REQUIRED CONFIG HINTS ${LLVM_DIR} NO_CMAKE_FIND_ROOT_PATH)
find_package(Clang REQUIRED CONFIG HINTS ${Clang_DIR} ${LLVM_DIR}/../clang NO_CMAKE_FIND_ROOT_PATH)
find_package(Swift REQUIRED CONFIG HINTS "${Swift_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
if(LLDB_ENABLE_SWIFT_SUPPORT)
find_package(Swift REQUIRED CONFIG HINTS "${Swift_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
endif()

# We set LLVM_CMAKE_DIR so that GetSVN.cmake is found correctly when building SVNVersion.inc
set(LLVM_CMAKE_DIR ${LLVM_CMAKE_DIR} CACHE PATH "Path to LLVM CMake modules")
Expand Down Expand Up @@ -88,7 +90,9 @@ endif()
# CMake modules to be in that directory as well.
file(TO_CMAKE_PATH ${LLVM_DIR} LLVM_DIR)
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
list(APPEND CMAKE_MODULE_PATH "${SWIFT_CMAKE_DIR}")
if(LLDB_ENABLE_SWIFT_SUPPORT)
list(APPEND CMAKE_MODULE_PATH "${SWIFT_CMAKE_DIR}")
endif()

include(AddLLVM)
include(TableGen)
Expand Down Expand Up @@ -124,9 +128,12 @@ include_directories(
"${CMAKE_BINARY_DIR}/include"
"${LLVM_INCLUDE_DIRS}"
"${CLANG_INCLUDE_DIRS}"
"${SWIFT_INCLUDE_DIRS}"
"${SWIFT_MAIN_SRC_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/source")
if(LLDB_ENABLE_SWIFT_SUPPORT)
include_directories(
"${SWIFT_INCLUDE_DIRS}"
"${SWIFT_MAIN_SRC_DIR}/include")
endif()

if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestCase(TestBase):
@swiftTest
def test_swift_po_address(self):
self.build()
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
Expand All @@ -20,6 +20,7 @@ def test_swift_po_address(self):
self.expect(f"dwim-print -O -- 0x{hex_addr}", patterns=[f"Object@0x0*{hex_addr}"])
self.expect(f"dwim-print -O -- {addr}", patterns=[f"Object@0x0*{hex_addr}"])

@swiftTest
def test_swift_po_non_address_hex(self):
"""No special handling of non-memory integer values."""
self.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,29 @@ class TestSwiftErrorBreakpoint(TestBase):
@swiftTest
def test_swift_error_no_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
self.do_tests(None, True)

@swiftTest
def test_swift_error_matching_base_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
self.do_tests("EnumError", True)

@swiftTest
def test_swift_error_matching_full_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
self.do_tests("a.EnumError", True)

@swiftTest
def test_swift_error_bogus_typename(self):
"""Tests that swift error throws are correctly caught by the Swift Error breakpoint"""
self.build()
self.do_tests("NoSuchErrorHere", False)

def setUp(self):
TestBase.setUp(self)
self.build()

def do_tests(self, typename, should_stop):
self.do_test(typename, should_stop, self.create_breakpoint_with_api)
Expand Down