Skip to content

Commit 8906a57

Browse files
committed
build: split out the SDK overlay
This splits out the SDK overlay component and libdispatch runtime itself. Doing so enables the re-use of libdispatch with and without swift and makes the behaviour similar across Darwin and other platforms.
1 parent b096ec0 commit 8906a57

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

src/CMakeLists.txt

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,41 @@ target_sources(dispatch
7272
PRIVATE
7373
block.cpp)
7474
if(HAVE_OBJC)
75+
# TODO(compnerd) split DispatchStubs.cc into a separate component for the ObjC
76+
# registration and a separate component for the swift compiler's emission of a
77+
# call to the ObjC autorelease elision entry point.
7578
target_sources(dispatch
7679
PRIVATE
7780
data.m
78-
object.m)
81+
object.m
82+
swift/DispatchStubs.cc)
7983
endif()
8084
if(ENABLE_SWIFT)
8185
set(swift_optimization_flags)
8286
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
8387
set(swift_optimization_flags -O)
8488
endif()
89+
90+
# TODO(compnerd) fix the swift compiler to directly call the swift entry point
91+
# if ObjC Interop is disabled to avoid having the stub for the ObjC
92+
# autorelease elision entry point
93+
add_library(DispatchStubs
94+
OBJECT
95+
swift/DispatchStubs.cc)
96+
target_include_directories(DispatchStubs
97+
PRIVATE
98+
${PROJECT_SOURCE_DIR})
99+
set_target_properties(DispatchStubs
100+
PROPERTIES
101+
POSITION_INDEPENDENT_CODE YES)
102+
85103
add_swift_library(swiftDispatch
86104
MODULE_NAME
87105
Dispatch
88106
MODULE_LINK_NAME
89107
dispatch
90108
MODULE_PATH
91109
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
92-
OUTPUT
93-
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
94110
SOURCES
95111
swift/Block.swift
96112
swift/Data.swift
@@ -110,23 +126,14 @@ if(ENABLE_SWIFT)
110126
-I ${PROJECT_SOURCE_DIR}
111127
-I/usr/include
112128
${swift_optimization_flags}
129+
LINK_FLAGS
130+
$<TARGET_OBJECTS:DispatchStubs>
113131
DEPENDS
114-
${PROJECT_SOURCE_DIR}/dispatch/module.modulemap)
115-
116-
get_filename_component(swift_toolchain ${CMAKE_SWIFT_COMPILER} DIRECTORY)
117-
get_filename_component(swift_toolchain ${swift_toolchain} DIRECTORY)
118-
set(swift_runtime_libdir ${swift_toolchain}/lib/${swift_dir}/${swift_os}/${swift_arch})
119-
120-
target_sources(dispatch
121-
PRIVATE
122-
swift/DispatchStubs.cc
123-
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
124-
${swift_runtime_libdir}/swiftrt.o)
125-
if(CMAKE_BUILD_TYPE MATCHES Debug)
126-
target_link_libraries(dispatch
127-
PRIVATE
128-
swiftSwiftOnoneSupport)
129-
endif()
132+
${PROJECT_SOURCE_DIR}/dispatch/module.modulemap
133+
module-map-symlinks
134+
DispatchStubs
135+
TARGET_FILES
136+
swiftDispatch_TARGET_FILES)
130137
endif()
131138
if(ENABLE_DTRACE)
132139
dtrace_usdt_probe(${CMAKE_CURRENT_SOURCE_DIR}/provider.d
@@ -231,8 +238,6 @@ add_custom_command(TARGET dispatch POST_BUILD
231238
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:dispatch> .libs
232239
COMMENT "Copying libdispatch to .libs")
233240

234-
get_swift_host_arch(SWIFT_HOST_ARCH)
235-
236241
install(TARGETS
237242
dispatch
238243
DESTINATION
@@ -242,6 +247,18 @@ if(ENABLE_SWIFT)
242247
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
243248
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
244249
DESTINATION
245-
"${INSTALL_TARGET_DIR}/${SWIFT_HOST_ARCH}")
250+
${INSTALL_TARGET_DIR}/${swift_arch})
251+
252+
if(BUILD_SHARED_LIBS)
253+
set(library_kind SHARED)
254+
else()
255+
set(library_kind STATIC)
256+
endif()
257+
set(swiftDispatch_OUTPUT_FILE
258+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_${library_kind}_LIBRARY_PREFIX}swiftDispatch${CMAKE_${library_kind}_LIBRARY_SUFFIX})
259+
install(FILES
260+
${swiftDispatch_OUTPUT_FILE}
261+
DESTINATION
262+
${INSTALL_TARGET_DIR})
246263
endif()
247264

tests/CMakeLists.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ if(BSD_OVERLAY_FOUND)
5656
PRIVATE
5757
${BSD_OVERLAY_LDFLAGS})
5858
endif()
59-
if(ENABLE_SWIFT)
60-
target_link_libraries(bsdtestharness
61-
PRIVATE
62-
swiftCore-${swift_os}-${swift_arch}
63-
swiftSwiftOnoneSupport-${swift_os}-${swift_arch})
64-
endif()
6559

6660
function(add_unit_test name)
6761
set(options DISABLED_TEST;NO_BSD_OVERLAY)
@@ -83,10 +77,6 @@ function(add_unit_test name)
8377
# For testing in swift.org CI system; make deadlines lenient by default
8478
# to reduce probability of test failures due to machine load.
8579
target_compile_options(${name} PRIVATE -DLENIENT_DEADLINES=1)
86-
target_link_libraries(${name}
87-
PRIVATE
88-
swiftCore-${swift_os}-${swift_arch}
89-
swiftSwiftOnoneSupport-${swift_os}-${swift_arch})
9080
endif()
9181
target_include_directories(${name}
9282
SYSTEM BEFORE PRIVATE
@@ -114,12 +104,6 @@ function(add_unit_test name)
114104
PRIVATE
115105
${BSD_OVERLAY_LDFLAGS})
116106
endif()
117-
if(ENABLE_SWIFT)
118-
target_link_libraries(${name}
119-
PRIVATE
120-
swiftCore-${swift_os}-${swift_arch}
121-
swiftSwiftOnoneSupport-${swift_os}-${swift_arch})
122-
endif()
123107
target_link_libraries(${name} PRIVATE bsdtests)
124108
add_test(NAME ${name}
125109
COMMAND bsdtestharness $<TARGET_FILE:${name}>)

0 commit comments

Comments
 (0)