diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e6519f5d..c040cb2a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ project(dispatch VERSION 1.3 LANGUAGES C CXX) +set(CMAKE_POSITION_INDEPENDENT_CODE YES) + if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") include(ClangClCompileRules) endif() diff --git a/dispatch/CMakeLists.txt b/dispatch/CMakeLists.txt index a7f5fc306..352915d91 100644 --- a/dispatch/CMakeLists.txt +++ b/dispatch/CMakeLists.txt @@ -1,10 +1,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin) set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap) -elseif(BUILD_SHARED_LIBS) - set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap) else() - set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic_static/module.modulemap) + set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap) endif() configure_file(dispatch-vfs.yaml.in ${CMAKE_BINARY_DIR}/dispatch-vfs-overlay.yaml diff --git a/dispatch/generic_static/module.modulemap b/dispatch/generic_static/module.modulemap deleted file mode 100644 index d5d64d2d1..000000000 --- a/dispatch/generic_static/module.modulemap +++ /dev/null @@ -1,19 +0,0 @@ -module Dispatch { - requires blocks - export * - link "dispatch" - link "BlocksRuntime" - link "DispatchStubs" -} - -module DispatchIntrospection [system] [extern_c] { - header "introspection.h" - export * -} - -module CDispatch [system] [extern_c] { - umbrella header "dispatch.h" - export * - requires blocks - link "dispatch" -} diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt index 945e87a7e..f6fde93ee 100644 --- a/src/BlocksRuntime/CMakeLists.txt +++ b/src/BlocksRuntime/CMakeLists.txt @@ -19,9 +19,6 @@ if(HAVE_OBJC AND CMAKE_DL_LIBS) ${CMAKE_DL_LIBS}) endif() -set_target_properties(BlocksRuntime PROPERTIES - POSITION_INDEPENDENT_CODE TRUE) - if(LINKER_SUPPORTS_BUILD_ID) target_link_options(BlocksRuntime PRIVATE "LINKER:--build-id=sha1") endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 320b6fcdc..846fb39b5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -82,19 +82,12 @@ if(ENABLE_DTRACE) endif() if(HAVE_OBJC) - # TODO(compnerd) split DispatchStubs.cc into a separate component for the ObjC - # registration and a separate component for the swift compiler's emission of a - # call to the ObjC autorelease elision entry point. target_sources(dispatch PRIVATE data.m object.m - swift/DispatchStubs.cc) + swift/DispatchStubs.m) endif() - -set_target_properties(dispatch PROPERTIES - POSITION_INDEPENDENT_CODE YES) - target_include_directories(dispatch PUBLIC ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index 4fffc84a4..38bef37af 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -1,9 +1,9 @@ -add_library(DispatchStubs STATIC - DispatchStubs.cc) -target_include_directories(DispatchStubs PRIVATE - ${PROJECT_SOURCE_DIR}) -set_target_properties(DispatchStubs PROPERTIES - POSITION_INDEPENDENT_CODE YES) +if(HAVE_OBJC) + add_library(DispatchStubs STATIC + DispatchStubs.m) + target_include_directories(DispatchStubs PRIVATE + ${PROJECT_SOURCE_DIR}) +endif() add_library(swiftDispatch Block.swift @@ -27,10 +27,14 @@ set_target_properties(swiftDispatch PROPERTIES Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swift INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/swift) target_link_libraries(swiftDispatch PRIVATE - DispatchStubs + $<$:DispatchStubs> BlocksRuntime::BlocksRuntime) target_link_libraries(swiftDispatch PUBLIC dispatch) +if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows") + target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath") + set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN") +endif() get_swift_host_arch(swift_arch) install(FILES @@ -43,12 +47,9 @@ install(TARGETS swiftDispatch ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} LIBRARY DESTINATION ${INSTALL_TARGET_DIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -if(NOT BUILD_SHARED_LIBS) +if(HAVE_OBJC AND NOT BUILD_SHARED_LIBS) set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs) install(TARGETS DispatchStubs EXPORT dispatchExports DESTINATION ${INSTALL_TARGET_DIR}) -elseif(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows") - target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath") - set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN") endif() diff --git a/src/swift/DispatchStubs.cc b/src/swift/DispatchStubs.m similarity index 84% rename from src/swift/DispatchStubs.cc rename to src/swift/DispatchStubs.m index dc320da29..1f72233eb 100644 --- a/src/swift/DispatchStubs.cc +++ b/src/swift/DispatchStubs.m @@ -11,13 +11,6 @@ //===----------------------------------------------------------------------===// #include -#include - -#if defined(__ELF__) || defined(__MACH__) || defined(__WASM__) -#define DISPATCH_RUNTIME_STDLIB_INTERFACE __attribute__((__visibility__("default"))) -#else -#define DISPATCH_RUNTIME_STDLIB_INTERFACE __declspec(dllexport) -#endif #if USE_OBJC @protocol OS_dispatch_source; @@ -34,11 +27,9 @@ @protocol OS_dispatch_source_vnode; @protocol OS_dispatch_source_write; -// #include -__attribute__((constructor)) +__attribute__((__constructor__)) static void _dispatch_overlay_constructor() { - Class source = objc_lookUpClass("OS_dispatch_source"); - if (source) { + if (Class source = objc_lookUpClass("OS_dispatch_source")) { class_addProtocol(source, @protocol(OS_dispatch_source)); class_addProtocol(source, @protocol(OS_dispatch_source_mach_send)); class_addProtocol(source, @protocol(OS_dispatch_source_mach_recv)); @@ -54,5 +45,4 @@ static void _dispatch_overlay_constructor() { class_addProtocol(source, @protocol(OS_dispatch_source_write)); } } - #endif /* USE_OBJC */