Skip to content

Commit 34a1a69

Browse files
committed
build: improve swift build/integration
Add explicit links against the swift runtime for the tests which may use the swift runtime. This prevents link failures for the swift tests. Install the swiftmodule and swiftdoc into the installed image. Correct the modulemap installation. Fix a typo in the header installation.
1 parent a28fc2b commit 34a1a69

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

CMakeLists.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,32 @@ dispatch_common_warnings()
3333
option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON)
3434
set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
3535

36-
# TODO(compnerd) swift options
36+
option(ENABLE_SWIFT "enable libdispatch swift overlay" OFF)
37+
if(ENABLE_SWIFT)
38+
if(NOT CMAKE_SWIFT_COMPILER)
39+
message(FATAL_ERROR "CMAKE_SWIFT_COMPILER must be defined to enable swift")
40+
endif()
41+
42+
get_filename_component(SWIFT_TOOLCHAIN ${CMAKE_SWIFT_COMPILER} DIRECTORY)
43+
get_filename_component(SWIFT_TOOLCHAIN ${SWIFT_TOOLCHAIN} DIRECTORY)
44+
45+
string(TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
46+
set(SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN}/lib/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR})
47+
48+
add_library(swiftCore
49+
SHARED IMPORTED GLOBAL)
50+
set_target_properties(swiftCore
51+
PROPERTIES
52+
IMPORTED_LOCATION
53+
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
54+
55+
add_library(swiftSwiftOnoneSupport
56+
SHARED IMPORTED GLOBAL)
57+
set_target_properties(swiftSwiftOnoneSupport
58+
PROPERTIES
59+
IMPORTED_LOCATION
60+
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
61+
endif()
3762

3863
option(BUILD_SHARED_LIBS "build shared libraries" ON)
3964

dispatch/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ install(FILES
1414
source.h
1515
time.h
1616
DESTINATION
17-
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch/)
17+
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch)
1818
if(ENABLE_SWIFT)
19+
get_filename_component(MODULE_MAP module.modulemap REALPATH)
1920
install(FILES
20-
module.modulemap
21+
${MODULE_MAP}
2122
DESTINATION
22-
${CMAKE_INSTALL_FULL_INCLUEDIR}/dispatch/)
23+
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch)
2324
endif()
2425

src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if(HAVE_OBJC)
6969
data.m
7070
object.m)
7171
endif()
72-
if(CMAKE_SWIFT_COMPILER)
72+
if(ENABLE_SWIFT)
7373
set(swift_optimization_flags)
7474
if(CMAKE_BUILD_TYPE MATCHES Release)
7575
set(swift_optimization_flags -O)
@@ -203,4 +203,11 @@ install(TARGETS
203203
dispatch
204204
DESTINATION
205205
"${CMAKE_INSTALL_FULL_LIBDIR}")
206+
if(ENABLE_SWIFT)
207+
install(FILES
208+
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
209+
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
210+
DESTINATION
211+
"${CMAKE_INSTALL_FULL_LIBDIR}/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR}")
212+
endif()
206213

tests/CMakeLists.txt

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_SOURCE_DIR}/private" "${CMAKE_CURRENT_BINARY_DIR}/dispatch")
33
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/leaks-wrapper.sh" "${CMAKE_CURRENT_BINARY_DIR}/leaks-wrapper")
44

5-
# TODO(compnerd) hoist this out of the test directory
6-
if(SWIFT_RUNTIME_LIBDIR)
7-
add_library(swiftCore SHARED IMPORTED)
8-
set_target_properties(swiftCore
9-
PROPERTIES
10-
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
11-
12-
add_library(swiftSwiftOnoneSupport SHARED IMPORTED)
13-
set_target_properties(swiftSwiftOnoneSupport
14-
PROPERTIES
15-
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
16-
endif()
17-
185
add_library(bsdtests
196
STATIC
207
bsdtests.c
@@ -74,10 +61,11 @@ function(add_unit_test name)
7461
${CMAKE_CURRENT_BINARY_DIR}
7562
${CMAKE_CURRENT_SOURCE_DIR}
7663
${CMAKE_SOURCE_DIR})
77-
if(CMAKE_SWIFT_COMPILER)
78-
# For testing in swift.org CI system; make deadlines lenient by default
79-
# to reduce probability of test failures due to machine load.
80-
target_compile_options(${name} PRIVATE -DLENIENT_DEADLINES=1)
64+
if(ENABLE_SWIFT)
65+
# For testing in swift.org CI system; make deadlines lenient by default
66+
# to reduce probability of test failures due to machine load.
67+
target_compile_options(${name} PRIVATE -DLENIENT_DEADLINES=1)
68+
target_link_libraries(${name} PRIVATE swiftCore swiftSwiftOnoneSupport)
8169
endif()
8270
if(WITH_BLOCKS_RUNTIME)
8371
target_include_directories(${name}

0 commit comments

Comments
 (0)