Skip to content

Commit 9fff09d

Browse files
committed
build: improve SourceKit handling of libdispatch
Avoid overwriting the `swiftCore` target in the SourceKit build. Instead, link to the explicit variant of the swiftCore. This tracks the dependency better and enables multiple parallel cross-compilations of the stdlib. Implicitly link against swiftCore when linking against libdispatch. Remove the extraneous link against the Blocks runtime on Linux. The `add_sourcekit_executable` call already handles this. Ensure that we enable the swift SDK overlay for libdispatch by sending it the path to the swift compiler.
1 parent c11a190 commit 9fff09d

File tree

6 files changed

+52
-19
lines changed

6 files changed

+52
-19
lines changed

tools/SourceKit/CMakeLists.txt

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,52 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
9898
CMAKE_ARGS
9999
-DCMAKE_C_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang
100100
-DCMAKE_CXX_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang++
101+
-DCMAKE_SWIFT_COMPILER=$<TARGET_FILE:swift>c
101102
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
103+
-DENABLE_SWIFT=YES
102104
BUILD_BYPRODUCTS
103-
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX})
104-
105+
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
106+
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
107+
STEP_TARGETS
108+
configure)
109+
110+
# CMake does not like the addition of INTERFACE_INCLUDE_DIRECTORIES without
111+
# the directory existing. Just create the location which will be populated
112+
# during the installation.
113+
ExternalProject_Get_Property(libdispatch install_dir)
114+
file(MAKE_DIRECTORY ${install_dir}/include)
115+
116+
# TODO(compnerd) this should be taken care of by the
117+
# INTERFACE_INCLUDE_DIRECTORIES below
105118
include_directories(AFTER
106-
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)
107-
link_directories(${SWIFT_PATH_TO_LIBDISPATCH_BUILD})
119+
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime
120+
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
121+
add_dependencies(libdispatch-configure
122+
swift
123+
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
124+
swiftSwiftOnoneSupport-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
125+
swiftCore-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
126+
swiftSwiftOnoneSupport-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})
108127
endif()
109128

110-
include_directories(AFTER ${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
111-
112-
add_library(dispatch UNKNOWN IMPORTED)
129+
ExternalProject_Get_Property(libdispatch install_dir)
130+
add_library(dispatch SHARED IMPORTED)
113131
set_target_properties(dispatch
114132
PROPERTIES
115-
IMPORTED_LOCATION ${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX})
116-
117-
add_library(swiftCore SHARED IMPORTED)
118-
set_target_properties(swiftCore PROPERTIES
119-
IMPORTED_LOCATION ${SOURCEKIT_BINARY_DIR}/lib/swift/linux/libswiftCore.so)
133+
IMPORTED_LOCATION
134+
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
135+
INTERFACE_INCLUDE_DIRECTORIES
136+
${install_dir}/include
137+
IMPORTED_LINK_INTERFACE_LIBRARIES
138+
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})
139+
140+
add_library(BlocksRuntime STATIC IMPORTED)
141+
set_target_properties(BlocksRuntime
142+
PROPERTIES
143+
IMPORTED_LOCATION
144+
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
145+
INTERFACE_INCLUDE_DIRECTORIES
146+
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)
120147

121148
set(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH TRUE)
122149
endif()

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ function(add_sourcekit_default_compiler_flags target)
6767
RESULT_VAR_NAME link_flags)
6868

6969
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
70+
# TODO(compnerd) this should really use target_compile_options but the use
71+
# of keyword and non-keyword flags prevents this
7072
list(APPEND c_compile_flags "-fblocks")
73+
# TODO(compnerd) this should really use target_link_libraries but the use of
74+
# explicit_llvm_config using target_link_libraries without keywords on
75+
# executables causes conflicts here
76+
list(APPEND link_flags "-L${SWIFT_PATH_TO_LIBDISPATCH_BUILD}")
7177
list(APPEND link_flags "-lBlocksRuntime")
78+
# NOTE(compnerd) since we do not use target_link_libraries, we do not get
79+
# the implicit dependency tracking. Add an explicit dependency until we can
80+
# use target_link_libraries.
81+
add_dependencies(${target} BlocksRuntime)
7282
endif()
7383

7484
# Convert variables to space-separated strings.

tools/SourceKit/tools/complete-test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ else()
55
endif()
66

77
if(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH)
8-
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch swiftCore)
8+
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch)
99
endif()
1010

1111
add_sourcekit_executable(complete-test

tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if(HAVE_UNICODE_LIBEDIT)
99
endif()
1010

1111
if(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH)
12-
set(SOURCEKITD_REPL_LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS} dispatch swiftCore)
12+
set(SOURCEKITD_REPL_LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS} dispatch)
1313
endif()
1414

1515
add_sourcekit_executable(sourcekitd-repl

tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else()
99
endif()
1010

1111
if(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH)
12-
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch swiftCore)
12+
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch)
1313
endif()
1414

1515
add_sourcekit_executable(sourcekitd-test

tools/SourceKit/tools/sourcekitd/bin/InProc/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ if (SOURCEKITD_BUILD_STATIC_INPROC)
4242
)
4343
endif()
4444

45-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
46-
target_link_libraries(sourcekitdInProc PUBLIC BlocksRuntime)
47-
endif()
48-
4945
if (SOURCEKIT_BUILT_STANDALONE)
5046
# Create the symlinks necessary to find the swift runtime.
5147
add_custom_command(TARGET sourcekitdInProc PRE_BUILD

0 commit comments

Comments
 (0)