Skip to content

FoundationNetworking: Split networking into its own module #2289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 71 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -117,10 +117,12 @@ endif()
# be able to remove this and just use
# `target_link_libraries(Foundation PRIVATE CoreFoundation)`.
set(CoreFoundation_LIBRARIES $<TARGET_FILE:CoreFoundation>)
set(CFURLSessionInterface_LIBRARIES $<TARGET_FILE:CFURLSessionInterface>)
get_target_property(CoreFoundation_LINK_LIBRARIES CoreFoundation LINK_LIBRARIES)
foreach(library ${CoreFoundation_LINK_LIBRARIES})
if(NOT library STREQUAL Threads::Threads)
list(APPEND CoreFoundation_LIBRARIES -l${library})
list(APPEND CFURLSessionInterface_LIBRARIES -l${library})
endif()
endforeach()

@@ -165,8 +167,6 @@ add_swift_library(Foundation
Foundation/Formatter.swift
Foundation/FoundationErrors.swift
Foundation/Host.swift
Foundation/HTTPCookie.swift
Foundation/HTTPCookieStorage.swift
Foundation/IndexPath.swift
Foundation/IndexSet.swift
Foundation/ISO8601DateFormatter.swift
@@ -235,7 +235,6 @@ add_swift_library(Foundation
Foundation/NSTimeZone.swift
Foundation/NSURL.swift
Foundation/NSURLError.swift
Foundation/NSURLRequest.swift
Foundation/NSUUID.swift
Foundation/NSValue.swift
Foundation/NumberFormatter.swift
@@ -264,31 +263,7 @@ add_swift_library(Foundation
Foundation/TimeZone.swift
Foundation/Unit.swift
Foundation/URL.swift
Foundation/URLAuthenticationChallenge.swift
Foundation/URLCache.swift
Foundation/URLComponents.swift
Foundation/URLCredential.swift
Foundation/URLCredentialStorage.swift
Foundation/URLProtectionSpace.swift
Foundation/URLProtocol.swift
Foundation/URLRequest.swift
Foundation/URLResponse.swift
Foundation/URLSession/BodySource.swift
Foundation/URLSession/Configuration.swift
Foundation/URLSession/http/HTTPMessage.swift
Foundation/URLSession/http/HTTPURLProtocol.swift
Foundation/URLSession/libcurl/EasyHandle.swift
Foundation/URLSession/libcurl/libcurlHelpers.swift
Foundation/URLSession/libcurl/MultiHandle.swift
Foundation/URLSession/Message.swift
Foundation/URLSession/NativeProtocol.swift
Foundation/URLSession/ftp/FTPURLProtocol.swift
Foundation/URLSession/TaskRegistry.swift
Foundation/URLSession/TransferState.swift
Foundation/URLSession/URLSession.swift
Foundation/URLSession/URLSessionConfiguration.swift
Foundation/URLSession/URLSessionDelegate.swift
Foundation/URLSession/URLSessionTask.swift
Foundation/UserDefaults.swift
Foundation/UUID.swift
Foundation/XMLDocument.swift
@@ -303,7 +278,6 @@ add_swift_library(Foundation
-F${CMAKE_CURRENT_BINARY_DIR}
LINK_FLAGS
${CoreFoundation_LIBRARIES}
${CURL_LIBRARIES}
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY}
${LIBXML2_LIBRARIES}
${libdispatch_ldflags}
@@ -331,6 +305,75 @@ add_swift_library(Foundation
CoreFoundation
$<$<PLATFORM_ID:Windows>:CoreFoundationResources>)

add_swift_library(FoundationNetworking
MODULE_NAME
FoundationNetworking
MODULE_LINK_NAME
FoundationNetworking
MODULE_PATH
${CMAKE_CURRENT_BINARY_DIR}/swift/FoundationNetworking.swiftmodule
SOURCES
Foundation/Boxing.swift
Foundation/NSURLRequest.swift
Foundation/HTTPCookie.swift
Foundation/HTTPCookieStorage.swift
Foundation/URLAuthenticationChallenge.swift
Foundation/URLCache.swift
Foundation/URLCredential.swift
Foundation/URLCredentialStorage.swift
Foundation/URLProtectionSpace.swift
Foundation/URLProtocol.swift
Foundation/URLRequest.swift
Foundation/URLResponse.swift
Foundation/URLSession/BodySource.swift
Foundation/URLSession/Configuration.swift
Foundation/URLSession/http/HTTPMessage.swift
Foundation/URLSession/http/HTTPURLProtocol.swift
Foundation/URLSession/libcurl/EasyHandle.swift
Foundation/URLSession/libcurl/libcurlHelpers.swift
Foundation/URLSession/libcurl/MultiHandle.swift
Foundation/URLSession/Message.swift
Foundation/URLSession/NativeProtocol.swift
Foundation/URLSession/NetworkingSpecific.swift
Foundation/URLSession/ftp/FTPURLProtocol.swift
Foundation/URLSession/TaskRegistry.swift
Foundation/URLSession/TransferState.swift
Foundation/URLSession/URLSession.swift
Foundation/URLSession/URLSessionConfiguration.swift
Foundation/URLSession/URLSessionDelegate.swift
Foundation/URLSession/URLSessionTask.swift
TARGET
${CMAKE_C_COMPILER_TARGET}
CFLAGS
${MSVCRT_C_FLAGS}
-F${CMAKE_CURRENT_BINARY_DIR}
LINK_FLAGS
${MSVCRT_LINK_FLAGS}
-L${CMAKE_CURRENT_BINARY_DIR}
${libdispatch_ldflags}
-lFoundation
${Foundation_INTERFACE_LIBRARIES}
${CFURLSessionInterface_LIBRARIES}
${CURL_LIBRARIES}
${Foundation_RPATH}
${WORKAROUND_SR9138}
${WORKAROUND_SR9995}
SWIFT_FLAGS
-DDEPLOYMENT_RUNTIME_SWIFT
-DNS_BUILDING_FOUNDATION_NETWORKING
${deployment_enable_libdispatch}
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
${libdispatch_cflags}
${swift_enable_testing}
${swift_optimization_flags}
DEPENDS
uuid
CoreFoundation
$<$<PLATFORM_ID:Windows>:CoreFoundationResources>
Foundation)



if(NOT BUILD_SHARED_LIBS)
set(Foundation_INTERFACE_LIBRARIES
-L${install_dir}/usr/lib
1 change: 0 additions & 1 deletion CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
#include <CoreFoundation/CFXMLInterface.h>
#include <CoreFoundation/CFRegularExpression.h>
#include <CoreFoundation/CFLogUtilities.h>
#include <CoreFoundation/CFURLSessionInterface.h>
#include <CoreFoundation/CFDateIntervalFormatter.h>
#include <CoreFoundation/ForFoundationOnly.h>
#include <CoreFoundation/CFCharacterSetPriv.h>
102 changes: 100 additions & 2 deletions CoreFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -316,6 +316,21 @@ add_framework(CoreFoundation
URL.subproj/CFURLComponents.c
URL.subproj/CFURLComponents_URIParser.c
URL.subproj/CFURLSessionInterface.c)

add_framework(CFURLSessionInterface
${FRAMEWORK_LIBRARY_TYPE}
FRAMEWORK_DIRECTORY
CoreFoundation_FRAMEWORK_DIRECTORY
MODULE_MAP
URL.subproj/module.modulemap
PRIVATE_HEADERS
URL.subproj/CFURLSessionInterface.h
PUBLIC_HEADERS
URL.subproj/CFURLSessionInterface.h
SOURCES
URL.subproj/CFURLSessionInterface.c)
add_dependencies(CFURLSessionInterface CoreFoundation)

if(CMAKE_SYSTEM_NAME STREQUAL Windows)
add_library(CoreFoundationResources OBJECT
CoreFoundation.rc)
@@ -337,38 +352,63 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android)
target_compile_definitions(CoreFoundation
PRIVATE
-D_GNU_SOURCE)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-D_GNU_SOURCE)
if(HAVE_SCHED_GETAFFINITY)
target_compile_definitions(CoreFoundation
PRIVATE
-DHAVE_SCHED_GETAFFINITY)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-DHAVE_SCHED_GETAFFINITY)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
# NOTE(compnerd) we only support building with the dynamic CRT as using the
# static CRT causes problems for users of the library.
target_compile_definitions(CoreFoundation
PRIVATE
-D_DLL)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-D_DLL)
if(BUILD_SHARED_LIBS)
target_compile_definitions(CoreFoundation
PRIVATE
-D_WINDLL)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-D_WINDLL)
endif()
target_compile_definitions(CoreFoundation
PRIVATE
-DCURL_STATICLIB)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-DCURL_STATICLIB)
endif()
target_compile_definitions(CoreFoundation
PRIVATE
-DU_SHOW_DRAFT_API
-DCF_BUILDING_CF)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-DU_SHOW_DRAFT_API
-DCF_BUILDING_CF)
if(CF_DEPLOYMENT_SWIFT)
target_compile_definitions(CoreFoundation
PRIVATE
-DDEPLOYMENT_RUNTIME_SWIFT)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-DDEPLOYMENT_RUNTIME_SWIFT)
else()
target_compile_definitions(CoreFoundation
PRIVATE
-DDEPLOYMENT_RUNTIME_C)
target_compile_definitions(CFURLSessionInterface
PRIVATE
-DDEPLOYMENT_RUNTIME_C)
endif()
target_compile_definitions(CoreFoundation
PRIVATE
@@ -386,7 +426,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
PRIVATE
${LIBXML2_INCLUDE_DIR})
find_package(CURL REQUIRED)
target_include_directories(CoreFoundation
target_include_directories(CFURLSessionInterface
PRIVATE
${CURL_INCLUDE_DIRS})
find_package(ICU COMPONENTS uc i18n REQUIRED)
@@ -398,27 +438,44 @@ target_include_directories(CoreFoundation
PRIVATE
${CF_PATH_TO_LIBDISPATCH_SOURCE}
${CF_PATH_TO_LIBDISPATCH_BUILD}/tests)
target_include_directories(CFURLSessionInterface
PRIVATE
${CF_PATH_TO_LIBDISPATCH_SOURCE}
${CF_PATH_TO_LIBDISPATCH_BUILD}/tests)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_include_directories(CoreFoundation
SYSTEM PRIVATE
${CF_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)
target_include_directories(CFURLSessionInterface
SYSTEM PRIVATE
${CF_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)
endif()

if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
target_compile_options(CoreFoundation
PRIVATE
$<$<COMPILE_LANGUAGE:C>:/FI${PROJECT_SOURCE_DIR}/Base.subproj/CoreFoundation_Prefix.h>)
target_compile_options(CFURLSessionInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does CFURLSessionInterface use the CoreFoundation prefix header? (which seems like a PCH attempt)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm keeping this, in case.

PRIVATE
$<$<COMPILE_LANGUAGE:C>:/FI${PROJECT_SOURCE_DIR}/Base.subproj/CoreFoundation_Prefix.h>)
else()
target_compile_options(CoreFoundation
PRIVATE
$<$<COMPILE_LANGUAGE:C>:-include;${PROJECT_SOURCE_DIR}/Base.subproj/CoreFoundation_Prefix.h>)
target_compile_options(CFURLSessionInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

PRIVATE
$<$<COMPILE_LANGUAGE:C>:-include;${PROJECT_SOURCE_DIR}/Base.subproj/CoreFoundation_Prefix.h>)
endif()

if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
target_compile_options(CoreFoundation
PRIVATE
-fblocks
/EHsc)
target_compile_options(CFURLSessionInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does CFURLSessionInterface use blocks? Or exceptions /EHsc enables exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like these two should be a baseline for all CF code, and will keep them as-is.

PRIVATE
-fblocks
/EHsc)
else()
target_compile_options(CoreFoundation
PRIVATE
@@ -427,16 +484,29 @@ else()
-fdollars-in-identifiers
-fexceptions
-fno-common)
target_compile_options(CFURLSessionInterface
PRIVATE
-fblocks
-fconstant-cfstrings
-fdollars-in-identifiers
-fexceptions
-fno-common)
endif()
if(CF_DEPLOYMENT_SWIFT)
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
target_compile_options(CoreFoundation
PRIVATE
/clang:-fcf-runtime-abi=swift)
target_compile_options(CFURLSessionInterface
PRIVATE
/clang:-fcf-runtime-abi=swift)
else()
target_compile_options(CoreFoundation
PRIVATE
-fcf-runtime-abi=swift)
target_compile_options(CFURLSessionInterface
PRIVATE
-fcf-runtime-abi=swift)
endif()
endif()

@@ -450,12 +520,24 @@ target_compile_options(CoreFoundation
-Wno-int-conversion
-Wno-unused-function
-Wno-microsoft-enum-forward-reference)
target_compile_options(CFURLSessionInterface
PRIVATE
-Wno-shorten-64-to-32
-Wno-deprecated-declarations
-Wno-unreachable-code
-Wno-conditional-uninitialized
-Wno-unused-variable
-Wno-int-conversion
-Wno-unused-function
-Wno-microsoft-enum-forward-reference)

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_libraries(CoreFoundation
PRIVATE
${CURL_LIBRARIES}
${LIBXML2_LIBRARIES})
target_link_libraries(CFURLSessionInterface
PRIVATE
${CURL_LIBRARIES})
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Android)
target_link_libraries(CoreFoundation
@@ -473,26 +555,42 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
Secur32
User32
mincore)
target_link_libraries(CFURLSessionInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you probably don't need to link against most of these libraries. WS2_32 and mincore are probably all that are needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't test Windows builds at the moment; is it okay if I leave them in and you can remove them later?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine to me - unlike Unix, the semantics on Windows are that they will be dropped if unused anyways.

PRIVATE
AdvAPI32
Secur32
User32
mincore)
endif()
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_libraries(CoreFoundation
PRIVATE
m)
target_link_libraries(CFURLSessionInterface
PRIVATE
m)
endif()
target_link_libraries(CoreFoundation
PRIVATE
dispatch)
target_link_libraries(CFURLSessionInterface
PRIVATE
dispatch)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_libraries(CoreFoundation
PRIVATE
icucore)
target_link_libraries(CFURLSessionInterface
PRIVATE
icucore)
set_target_properties(CoreFoundation
PROPERTIES LINK_FLAGS
-Xlinker;-alias_list;-Xlinker;Base.subproj/DarwinSymbolAliases;-twolevel_namespace;-sectcreate;__UNICODE;__csbitmaps;CharacterSets/CFCharacterSetBitmaps.bitmap;-sectcreate;__UNICODE;__properties;CharacterSets/CFUniCharPropertyDatabase.data;-sectcreate;__UNICODE;__data;CharacterSets/CFUnicodeData-L.mapping;-segprot;__UNICODE;r;r)
endif()

install(TARGETS
CoreFoundation
CFURLSessionInterface
DESTINATION
"${CMAKE_INSTALL_FULL_LIBDIR}")
install(DIRECTORY
Loading