Skip to content

Commit 2ea75b0

Browse files
authored
Merge pull request swiftlang#79455 from etcwilde/ewilde/stdlib-rebuild-macos-concurrency
CMake: Find Dispatch module
2 parents 6ae30ed + a0682cb commit 2ea75b0

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,8 @@ if(SWIFT_ENABLE_NEW_RUNTIME_BUILD)
16321632
-DCMAKE_COLOR_DIAGNOSTICS:BOOLEAN=${CMAKE_COLOR_DIAGNOSTICS}
16331633
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
16341634
-DSwiftCore_PLATFORM_SUBDIR=${SWIFT_SDK_${sdk}_LIB_SUBDIR}
1635-
-DSwiftCore_ARCH_SUBDIR=${arch})
1635+
-DSwiftCore_ARCH_SUBDIR=${arch}
1636+
-DSwiftCore_ENABLE_CONCURRENCY=YES)
16361637
if(NOT ${CMAKE_CROSSCOMPILING})
16371638
add_dependencies("${stdlib_target}" swift-frontend)
16381639
endif()

Runtimes/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ defaulted_option(SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS "Resolve ab
112112
defaulted_option(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT "Add symbols for runtime backdeployment")
113113
defaulted_option(SwiftCore_ENABLE_STDLIB_TRACING "Enable tracing in the runtime. Assumes the presence of os_log(3) and the os_signpost(3) API.")
114114
defaulted_option(SwiftCore_ENABLE_CONCURRENCY "Enable Concurrency runtime support")
115+
defaulted_set(SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR STRING "Default Concurrency global executor implementation")
115116
option(SwiftCore_ENABLE_UNICODE_DATA "Include unicode data in Swift runtimes" ON)
116117
option(SwiftCore_ENABLE_SHORT_MANGLING_LOOKUPS "Build with fast-path context descriptor lookups based on well-known short manglings." ON)
117118
option(SwiftCore_ENABLE_FILESYSTEM_SUPPORT "Build for systems that have a filesystem" ON)

Runtimes/Core/Concurrency/dispatch.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
find_package(dispatch QUIET)
2+
find_package(dispatch QUIET REQUIRED)
33

44
target_sources(swift_Concurrency PRIVATE
55
DispatchGlobalExecutor.cpp)
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#[=======================================================================[.rst:
2+
Finddispatch
3+
------------
4+
5+
Find libdispatch, deferring to dispatchConfig.cmake when requested.
6+
This is meant to find the C implementation of libdispatch for use as the
7+
executor for Swift concurrency. This library is not intended for use by
8+
third-party program on Linux or Windows.
9+
10+
Imported Targets
11+
^^^^^^^^^^^^^^^^
12+
13+
The following :prop_tgt:`IMPORTED` TARGETS may be defined:
14+
15+
``dispatch``
16+
17+
Hint Variables
18+
^^^^^^^^^^^^^^
19+
20+
``swift_SDKROOT``
21+
Set the path to the Swift SDK installation.
22+
This only affects Linux and Windows builds.
23+
Apple builds always use the library provided by the SDK.
24+
25+
``dispatch_STATIC``
26+
Look for the libdispatch static archive instead of the dynamic library.
27+
This only affects Linux. Apple builds always use the
28+
dynamic library provided by the SDK. Windows does not currently have a static
29+
libdispatch implementation.
30+
31+
Result Variables
32+
^^^^^^^^^^^^^^^^
33+
34+
The module may set the following variables if `dispatch_DIR` is not set.
35+
36+
``dispatch_FOUND``
37+
true if dispatch headers and libraries were found
38+
39+
``dispatch_INCLUDE_DIR``
40+
the directory containing the libdispatch headers
41+
42+
``dispatch_LIBRARIES`` OR ``dispatch_IMPLIB``
43+
the libraries to be linked
44+
45+
#]=======================================================================]
46+
47+
# If the dispatch_DIR is specified, look there instead. The cmake-generated
48+
# config file is more accurate, but requires that the SDK has one available.
49+
if(dispatch_DIR)
50+
if(dispatch_FIND_REQUIRED)
51+
list(APPEND args REQUIRED)
52+
endif()
53+
if(dispatch_FIND_QUIETLY)
54+
list(APPEND args QUIET)
55+
endif()
56+
find_package(dispatch NO_MODULE ${args})
57+
return()
58+
endif()
59+
60+
include(FindPackageHandleStandardArgs)
61+
62+
if(APPLE)
63+
# When building for Apple platforms, libdispatch always comes from within the
64+
# SDK as a tbd for a shared library in the shared cache.
65+
find_path(dispatch_INCLUDE_DIR "dispatch/dispatch.h")
66+
find_library(dispatch_IMPLIB
67+
NAMES "libdispatch.tbd"
68+
PATH "usr/lib"
69+
PATH_SUFFIXES system)
70+
add_library(dispatch SHARED IMPORTED GLOBAL)
71+
set_target_properties(dispatch PROPERTIES
72+
IMPORTED_IMPLIB "${dispatch_IMPLIB}"
73+
INTERFACE_INCLUDE_DIRECTORIES "${dispatch_INCLUDE_DIR}")
74+
find_package_handle_standard_args(dispatch DEFAULT_MSG
75+
dispatch_IMPLIB dispatch_INCLUDE_DIR)
76+
elseif(LINUX)
77+
if(dispatch_STATIC)
78+
find_path(dispatch_INCLUDE_DIR
79+
"dispatch/dispatch.h"
80+
HINTS "${Swift_SDKROOT}/usr/lib/swift_static")
81+
find_library(dispatch_LIBRARY
82+
NAMES "libdispatch.a"
83+
HINTS "${Swift_SDKROOT}/usr/lib/swift_static/linux")
84+
add_library(dispatch STATIC IMPORTED GLOBAL)
85+
else()
86+
find_path(dispatch_INCLUDE_DIR
87+
"dispatch/dispatch.h"
88+
HINTS "${Swift_SDKROOT}/usr/lib/swift")
89+
find_library(dispatch_LIBRARY
90+
NAMES "libdispatch.so"
91+
HINTS "${Swift_SDKROOT}/usr/lib/swift/linux")
92+
add_library(dispatch SHARED IMPORTED GLOBAL)
93+
endif()
94+
set_target_properties(dispatch
95+
IMPORTED_LOCATION "${dispatch_LIBRARY}"
96+
INTERFACE_INCLUDE_DIRECTORIES "${dispatch_INCLUDE_DIR}")
97+
find_package_handle_standard_args(dispatch DEFAULT_MSG
98+
dispatch_LIBRARY dispatch_INCLUDE_DIR)
99+
elseif(WIN32)
100+
find_path(dispatch_INCLUDE_DIR
101+
"dispatch/dispatch.h"
102+
HINTS
103+
"${Swift_SDKROOT}/usr/include"
104+
"$ENV{SDKROOT}/usr/include")
105+
find_library(dispatch_LIBRARY
106+
NAMES "dispatch.lib"
107+
HINTS
108+
"${Swift_SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
109+
"${Swift_SDKROOT}/usr/lib/swift"
110+
"$ENV{SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
111+
"$ENV{SDKROOT}/usr/lib/swift")
112+
113+
add_library(dispatch SHARED IMPORTED GLOBAL)
114+
set_target_properties(dispatch
115+
IMPORTED_IMPLIB "${dispatch_LIBRARY}"
116+
INTERFACE_INCLUDE_DIRECTORIES "${dispatch_INCLUDE_DIR}")
117+
find_package_handle_standard_args(dispatch DEFAULT_MSG
118+
dispatch_IMPLIB dispatch_INCLUDE_DIR)
119+
else()
120+
message(FATAL_ERROR "Finddispatch.cmake module search not implemented for targeted platform\n"
121+
" Build corelibs libdispatch for your platform and set `dispatch_DIR` to"
122+
" the directory containing dispatchConfig.cmake\n")
123+
endif()

0 commit comments

Comments
 (0)