Skip to content

[cmake] Fix a few issues around swift cmake support build/test #37838

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
27 changes: 23 additions & 4 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,17 @@ function(add_swift_host_library name)
endif()

add_library(${name} ${libkind} ${ASHL_SOURCES})
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})

# Respect LLVM_COMMON_DEPENDS if it is set.
#
# LLVM_COMMON_DEPENDS if a global variable set in ./lib that provides targets
# such as swift-syntax or tblgen that all LLVM/Swift based tools depend on. If
# we don't have it defined, then do not add the dependency since some parts of
# swift host tools do not interact with LLVM/Swift tools and do not define
# LLVM_COMMON_DEPENDS.
if (LLVM_COMMON_DEPENDS)
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
endif()
if (NOT ASHL_PURE_SWIFT)
llvm_update_compile_flags(${name})
endif()
Expand Down Expand Up @@ -624,12 +634,21 @@ function(add_swift_host_tool executable)
_add_host_variant_c_compile_flags(${executable})
_add_host_variant_link_flags(${executable})
_add_host_variant_c_compile_link_flags(${executable})
target_link_directories(${executable} PRIVATE
${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR})

# Force executables linker language to be CXX so that we do not link using the
# host toolchain swiftc.
set_target_properties(${executable} PROPERTIES LINKER_LANGUAGE CXX)
add_dependencies(${executable} ${LLVM_COMMON_DEPENDS})

# Respect LLVM_COMMON_DEPENDS if it is set.
#
# LLVM_COMMON_DEPENDS if a global variable set in ./lib that provides targets
# such as swift-syntax or tblgen that all LLVM/Swift based tools depend on. If
# we don't have it defined, then do not add the dependency since some parts of
# swift host tools do not interact with LLVM/Swift tools and do not define
# LLVM_COMMON_DEPENDS.
if (LLVM_COMMON_DEPENDS)
add_dependencies(${executable} ${LLVM_COMMON_DEPENDS})
endif()

set_target_properties(${executable} PROPERTIES
FOLDER "Swift executables")
Expand Down
15 changes: 0 additions & 15 deletions validation-test/BuildSystem/swift-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# In the absence of fine grained tablegen dependencies we need to ensure that
# Swift's libraries all build after the LLVM & Clang tablegen-generated headers
# are generated. When building out-of-tree (as with build-script) LLVM & Clang's
# CMake configuration files create these targets as dummies so we can safely
# depend on them directly here (See: SR-6026)
# LLVM_COMMON_DEPENDS is a construct from the LLVM build system. It is a special
# purpose variable that provides common dependencies for all libraries, and
# executables generated when it is set. CMake's scoping rules enforce that these
# new dependencies will only be added to targets created under Swift's lib
# directory.
list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen clang-tablegen-targets)

# Add generated libSyntax headers to global dependencies.
list(APPEND LLVM_COMMON_DEPENDS swift-syntax-generated-headers)
list(APPEND LLVM_COMMON_DEPENDS swift-parse-syntax-generated-headers)

add_swift_host_library(TestCPPLib
STATIC
Expand Down