Skip to content

Commit 108b59d

Browse files
committed
build: explicitly link tests to swiftCore swiftOnoneSupport
Add explicit links against the swift runtime for the tests which may use the swift runtime. This prevents link failures for the swift tests.
1 parent 9ec74ed commit 108b59d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

dispatch/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ 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)
1919
install(FILES
2020
module.modulemap
2121
DESTINATION
22-
${CMAKE_INSTALL_FULL_INCLUEDIR}/dispatch/)
22+
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch)
2323
endif()
2424

tests/CMakeLists.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,26 @@ execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_SOURCE_DIR
33
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/leaks-wrapper.sh" "${CMAKE_CURRENT_BINARY_DIR}/leaks-wrapper")
44

55
# TODO(compnerd) hoist this out of the test directory
6-
if(SWIFT_RUNTIME_LIBDIR)
7-
add_library(swiftCore SHARED IMPORTED)
6+
if(CMAKE_SWIFT_COMPILER)
7+
get_filename_component(SWIFT_TOOLCHAIN ${CMAKE_SWIFT_COMPILER} DIRECTORY)
8+
get_filename_component(SWIFT_TOOLCHAIN ${SWIFT_TOOLCHAIN} DIRECTORY)
9+
10+
string(TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
11+
set(SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN}/lib/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR})
12+
13+
add_library(swiftCore
14+
SHARED IMPORTED GLOBAL)
815
set_target_properties(swiftCore
916
PROPERTIES
10-
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
17+
IMPORTED_LOCATION
18+
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
1119

12-
add_library(swiftSwiftOnoneSupport SHARED IMPORTED)
20+
add_library(swiftSwiftOnoneSupport
21+
SHARED IMPORTED GLOBAL)
1322
set_target_properties(swiftSwiftOnoneSupport
1423
PROPERTIES
15-
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
24+
IMPORTED_LOCATION
25+
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
1626
endif()
1727

1828
add_library(bsdtests
@@ -75,9 +85,10 @@ function(add_unit_test name)
7585
${CMAKE_CURRENT_SOURCE_DIR}
7686
${CMAKE_SOURCE_DIR})
7787
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)
88+
# For testing in swift.org CI system; make deadlines lenient by default
89+
# to reduce probability of test failures due to machine load.
90+
target_compile_options(${name} PRIVATE -DLENIENT_DEADLINES=1)
91+
target_link_libraries(${name} PRIVATE swiftCore swiftSwiftOnoneSupport)
8192
endif()
8293
if(WITH_BLOCKS_RUNTIME)
8394
target_include_directories(${name}

0 commit comments

Comments
 (0)