@@ -72,25 +72,60 @@ target_sources(dispatch
72
72
PRIVATE
73
73
block .cpp )
74
74
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.
75
78
target_sources (dispatch
76
79
PRIVATE
77
80
data.m
78
- object.m )
81
+ object.m
82
+ swift/DispatchStubs.cc )
79
83
endif ()
80
84
if (ENABLE_SWIFT )
81
85
set (swift_optimization_flags )
82
86
if (NOT CMAKE_BUILD_TYPE MATCHES Debug )
83
87
set (swift_optimization_flags -O )
84
88
endif ()
89
+
90
+ # NOTE(compnerd) Today regardless of whether or not ObjC interop is enabled,
91
+ # swift will use an autoreleased return value convention for certain CF
92
+ # functions (including some that are used/related to dispatch). This means
93
+ # that the swift compiler in callers to such functions will call the function,
94
+ # and then pass the result of the function to
95
+ # objc_retainAutoreleasedReturnValue. In a context where we have ObjC interop
96
+ # disabled, we do not have access to the objc runtime so an implementation of
97
+ # objc_retainAutoreleasedReturnValue is not available. To work around this, we
98
+ # provide a shim for objc_retainAutoreleasedReturnValue in DispatchStubs.cc
99
+ # that just calls retain on the object. Once we fix the swift compiler to
100
+ # switch to a different model for handling these arguments with objc-interop
101
+ # disabled these shims can be eliminated.
102
+ add_library (DispatchStubs
103
+ STATIC
104
+ swift/DispatchStubs.cc )
105
+ target_include_directories (DispatchStubs
106
+ PRIVATE
107
+ ${PROJECT_SOURCE_DIR} )
108
+ set_target_properties (DispatchStubs
109
+ PROPERTIES
110
+ POSITION_INDEPENDENT_CODE YES )
111
+
85
112
add_swift_library (swiftDispatch
113
+ CFLAGS
114
+ -fblocks
115
+ -fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/module.modulemap
116
+ DEPENDS
117
+ ${PROJECT_SOURCE_DIR} /dispatch/module.modulemap
118
+ DispatchStubs
119
+ LINK_FLAGS
120
+ -lDispatchStubs
121
+ -L $< TARGET_LINKER_FILE_DIR:dispatch>
122
+ -ldispatch
86
123
MODULE_NAME
87
124
Dispatch
88
125
MODULE_LINK_NAME
89
- dispatch
126
+ swiftDispatch
90
127
MODULE_PATH
91
128
${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftmodule
92
- OUTPUT
93
- ${CMAKE_CURRENT_BINARY_DIR} /swiftDispatch.o
94
129
SOURCES
95
130
swift/Block.swift
96
131
swift/Data.swift
@@ -101,32 +136,12 @@ if(ENABLE_SWIFT)
101
136
swift/Source.swift
102
137
swift/Time.swift
103
138
swift/Wrapper.swift
104
- TARGET
105
- ${CMAKE_C_COMPILER_TARGET}
106
- CFLAGS
107
- -fblocks
108
- -fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/module.modulemap
109
139
SWIFT_FLAGS
110
140
-I ${PROJECT_SOURCE_DIR}
111
141
-I/usr/include
112
142
${swift_optimization_flags}
113
- 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 ()
143
+ TARGET
144
+ ${CMAKE_C_COMPILER_TARGET} )
130
145
endif ()
131
146
if (ENABLE_DTRACE )
132
147
dtrace_usdt_probe (${CMAKE_CURRENT_SOURCE_DIR} /provider.d
@@ -231,8 +246,6 @@ add_custom_command(TARGET dispatch POST_BUILD
231
246
COMMAND ${CMAKE_COMMAND} -E copy $< TARGET_FILE:dispatch> .libs
232
247
COMMENT "Copying libdispatch to .libs" )
233
248
234
- get_swift_host_arch (SWIFT_HOST_ARCH )
235
-
236
249
install (TARGETS
237
250
dispatch
238
251
DESTINATION
@@ -242,6 +255,18 @@ if(ENABLE_SWIFT)
242
255
${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftmodule
243
256
${CMAKE_CURRENT_BINARY_DIR} /swift/Dispatch.swiftdoc
244
257
DESTINATION
245
- "${INSTALL_TARGET_DIR} /${SWIFT_HOST_ARCH} " )
258
+ ${INSTALL_TARGET_DIR} /${swift_arch} )
259
+
260
+ if (BUILD_SHARED_LIBS )
261
+ set (library_kind SHARED )
262
+ else ()
263
+ set (library_kind STATIC )
264
+ endif ()
265
+ set (swiftDispatch_OUTPUT_FILE
266
+ ${CMAKE_CURRENT_BINARY_DIR} /${CMAKE_${library_kind}_LIBRARY_PREFIX}swiftDispatch${CMAKE_${library_kind}_LIBRARY_SUFFIX} )
267
+ install (FILES
268
+ ${swiftDispatch_OUTPUT_FILE}
269
+ DESTINATION
270
+ ${INSTALL_TARGET_DIR} )
246
271
endif ()
247
272
0 commit comments