Skip to content

Commit 7bb6470

Browse files
committed
dispatch: remove DispatchStubs on non-ObjC targets
This is no longer required. Address the long standing FIXME and simplify the build.
1 parent 84ec97c commit 7bb6470

File tree

7 files changed

+18
-56
lines changed

7 files changed

+18
-56
lines changed

Diff for: CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ project(dispatch
1313
VERSION 1.3
1414
LANGUAGES C CXX)
1515

16+
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
17+
1618
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
1719
include(ClangClCompileRules)
1820
endif()

Diff for: dispatch/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11

22
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
33
set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap)
4-
elseif(BUILD_SHARED_LIBS)
5-
set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap)
64
else()
7-
set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic_static/module.modulemap)
5+
set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap)
86
endif()
97
configure_file(dispatch-vfs.yaml.in
108
${CMAKE_BINARY_DIR}/dispatch-vfs-overlay.yaml

Diff for: dispatch/generic_static/module.modulemap

-19
This file was deleted.

Diff for: src/BlocksRuntime/CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ if(HAVE_OBJC AND CMAKE_DL_LIBS)
1919
${CMAKE_DL_LIBS})
2020
endif()
2121

22-
set_target_properties(BlocksRuntime PROPERTIES
23-
POSITION_INDEPENDENT_CODE TRUE)
24-
2522
if(LINKER_SUPPORTS_BUILD_ID)
2623
target_link_options(BlocksRuntime PRIVATE "LINKER:--build-id=sha1")
2724
endif()

Diff for: src/CMakeLists.txt

+1-8
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,12 @@ if(ENABLE_DTRACE)
8282
endif()
8383

8484
if(HAVE_OBJC)
85-
# TODO(compnerd) split DispatchStubs.cc into a separate component for the ObjC
86-
# registration and a separate component for the swift compiler's emission of a
87-
# call to the ObjC autorelease elision entry point.
8885
target_sources(dispatch PRIVATE
8986
data.m
9087
object.m
91-
swift/DispatchStubs.cc)
88+
swift/DispatchStubs.m)
9289
endif()
9390

94-
95-
set_target_properties(dispatch PROPERTIES
96-
POSITION_INDEPENDENT_CODE YES)
97-
9891
target_include_directories(dispatch PUBLIC
9992
${PROJECT_BINARY_DIR}
10093
${PROJECT_SOURCE_DIR}

Diff for: src/swift/CMakeLists.txt

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
add_library(DispatchStubs STATIC
2-
DispatchStubs.cc)
3-
target_include_directories(DispatchStubs PRIVATE
4-
${PROJECT_SOURCE_DIR})
5-
set_target_properties(DispatchStubs PROPERTIES
6-
POSITION_INDEPENDENT_CODE YES)
1+
if(HAVE_OBJC)
2+
add_library(DispatchStubs STATIC
3+
DispatchStubs.m)
4+
target_include_directories(DispatchStubs PRIVATE
5+
${PROJECT_SOURCE_DIR})
6+
endif()
77

88
add_library(swiftDispatch
99
Block.swift
@@ -27,10 +27,14 @@ set_target_properties(swiftDispatch PROPERTIES
2727
Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swift
2828
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/swift)
2929
target_link_libraries(swiftDispatch PRIVATE
30-
DispatchStubs
30+
$<$<BOOL:${HAVE_OBJC}>:DispatchStubs>
3131
BlocksRuntime::BlocksRuntime)
3232
target_link_libraries(swiftDispatch PUBLIC
3333
dispatch)
34+
if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
35+
target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
36+
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
37+
endif()
3438

3539
get_swift_host_arch(swift_arch)
3640
install(FILES
@@ -43,12 +47,9 @@ install(TARGETS swiftDispatch
4347
ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
4448
LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
4549
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
46-
if(NOT BUILD_SHARED_LIBS)
50+
if(HAVE_OBJC AND NOT BUILD_SHARED_LIBS)
4751
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs)
4852
install(TARGETS DispatchStubs
4953
EXPORT dispatchExports
5054
DESTINATION ${INSTALL_TARGET_DIR})
51-
elseif(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
52-
target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
53-
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
5455
endif()

Diff for: src/swift/DispatchStubs.cc renamed to src/swift/DispatchStubs.m

+2-12
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include <dispatch/dispatch.h>
14-
#include <stdio.h>
15-
16-
#if defined(__ELF__) || defined(__MACH__) || defined(__WASM__)
17-
#define DISPATCH_RUNTIME_STDLIB_INTERFACE __attribute__((__visibility__("default")))
18-
#else
19-
#define DISPATCH_RUNTIME_STDLIB_INTERFACE __declspec(dllexport)
20-
#endif
2114

2215
#if USE_OBJC
2316
@protocol OS_dispatch_source;
@@ -34,11 +27,9 @@
3427
@protocol OS_dispatch_source_vnode;
3528
@protocol OS_dispatch_source_write;
3629

37-
// #include <dispatch/private.h>
38-
__attribute__((constructor))
30+
__attribute__((__constructor__))
3931
static void _dispatch_overlay_constructor() {
40-
Class source = objc_lookUpClass("OS_dispatch_source");
41-
if (source) {
32+
if (Class source = objc_lookUpClass("OS_dispatch_source")) {
4233
class_addProtocol(source, @protocol(OS_dispatch_source));
4334
class_addProtocol(source, @protocol(OS_dispatch_source_mach_send));
4435
class_addProtocol(source, @protocol(OS_dispatch_source_mach_recv));
@@ -54,5 +45,4 @@ static void _dispatch_overlay_constructor() {
5445
class_addProtocol(source, @protocol(OS_dispatch_source_write));
5546
}
5647
}
57-
5848
#endif /* USE_OBJC */

0 commit comments

Comments
 (0)