Skip to content

Commit 57c012c

Browse files
committed
FoundationNetworking: Split networking into its own module
This patch introduces a new module, FoundationNetworking, which will include all classes related to loading from remote URLs. Several types have been moved to that module, which downstream clients must import explicitly, e.g.: ``` #if canImport(FoundationNetworking) import FoundationNetworking #endif ``` - Split the CFURLSessionInterface files out of Core Foundation and into their own library, libCFURLSessionInterface. This is produced by the CF CMakeLists.txt file on non-Darwin platforms. Just like CF, we strongly discourage linking to this library directly. - Split URLSession and related classes (except for URL and URLComponents) into a new FoundationNetworking module (SwiftFoundationNetworking on Darwin). Note: 1. The features in Boxing.swift are needed to both modules. This file is compiled separately in both modules, and relies on a NS_BUILDING_FOUNDATION_NETWORKING compilation condition to compile correctly in FoundationNetworking 2. SPI that was used in InputStream is now available through a public struct named _InputStreamSPIForFoundationNetworkingUseOnly for FoundationNetworking to use. This isn’t API, much like _ObjectiveCBridgeable. Also: - Change some details to make tests fail without a fatal error for issues that aren’t programmer errors. - In some circumstances, CURL can set an immediate timeout reentrantly if the timeout callback invokes CURL hooks. Always dispatch the CURL hook call asynchronously from a request for an immediate timeout. - Types that have a `contentsOf url: URL` initializer can still accept non-file: URLs if FoundationNetworking is available in the address space of the current process (if it has been linked or dynamically loaded, for example). Loading non-file: URLs without this will result in a fatal error. Loading file: URLs will always succeed even in the absence of FoundationNetworking.
1 parent b520d55 commit 57c012c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1212
-177
lines changed

CMakeLists.txt

+76-28
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ endif()
117117
# be able to remove this and just use
118118
# `target_link_libraries(Foundation PRIVATE CoreFoundation)`.
119119
set(CoreFoundation_LIBRARIES $<TARGET_FILE:CoreFoundation>)
120+
set(CFURLSessionInterface_LIBRARIES $<TARGET_FILE:CFURLSessionInterface>)
120121
get_target_property(CoreFoundation_LINK_LIBRARIES CoreFoundation LINK_LIBRARIES)
121122
foreach(library ${CoreFoundation_LINK_LIBRARIES})
122123
if(NOT library STREQUAL Threads::Threads)
123124
list(APPEND CoreFoundation_LIBRARIES -l${library})
125+
list(APPEND CFURLSessionInterface_LIBRARIES -l${library})
124126
endif()
125127
endforeach()
126128

@@ -165,8 +167,6 @@ add_swift_library(Foundation
165167
Foundation/Formatter.swift
166168
Foundation/FoundationErrors.swift
167169
Foundation/Host.swift
168-
Foundation/HTTPCookie.swift
169-
Foundation/HTTPCookieStorage.swift
170170
Foundation/IndexPath.swift
171171
Foundation/IndexSet.swift
172172
Foundation/ISO8601DateFormatter.swift
@@ -235,7 +235,6 @@ add_swift_library(Foundation
235235
Foundation/NSTimeZone.swift
236236
Foundation/NSURL.swift
237237
Foundation/NSURLError.swift
238-
Foundation/NSURLRequest.swift
239238
Foundation/NSUUID.swift
240239
Foundation/NSValue.swift
241240
Foundation/NumberFormatter.swift
@@ -264,31 +263,7 @@ add_swift_library(Foundation
264263
Foundation/TimeZone.swift
265264
Foundation/Unit.swift
266265
Foundation/URL.swift
267-
Foundation/URLAuthenticationChallenge.swift
268-
Foundation/URLCache.swift
269266
Foundation/URLComponents.swift
270-
Foundation/URLCredential.swift
271-
Foundation/URLCredentialStorage.swift
272-
Foundation/URLProtectionSpace.swift
273-
Foundation/URLProtocol.swift
274-
Foundation/URLRequest.swift
275-
Foundation/URLResponse.swift
276-
Foundation/URLSession/BodySource.swift
277-
Foundation/URLSession/Configuration.swift
278-
Foundation/URLSession/http/HTTPMessage.swift
279-
Foundation/URLSession/http/HTTPURLProtocol.swift
280-
Foundation/URLSession/libcurl/EasyHandle.swift
281-
Foundation/URLSession/libcurl/libcurlHelpers.swift
282-
Foundation/URLSession/libcurl/MultiHandle.swift
283-
Foundation/URLSession/Message.swift
284-
Foundation/URLSession/NativeProtocol.swift
285-
Foundation/URLSession/ftp/FTPURLProtocol.swift
286-
Foundation/URLSession/TaskRegistry.swift
287-
Foundation/URLSession/TransferState.swift
288-
Foundation/URLSession/URLSession.swift
289-
Foundation/URLSession/URLSessionConfiguration.swift
290-
Foundation/URLSession/URLSessionDelegate.swift
291-
Foundation/URLSession/URLSessionTask.swift
292267
Foundation/UserDefaults.swift
293268
Foundation/UUID.swift
294269
Foundation/XMLDocument.swift
@@ -303,7 +278,6 @@ add_swift_library(Foundation
303278
-F${CMAKE_CURRENT_BINARY_DIR}
304279
LINK_FLAGS
305280
${CoreFoundation_LIBRARIES}
306-
${CURL_LIBRARIES}
307281
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY}
308282
${LIBXML2_LIBRARIES}
309283
${libdispatch_ldflags}
@@ -331,6 +305,80 @@ add_swift_library(Foundation
331305
CoreFoundation
332306
$<$<PLATFORM_ID:Windows>:CoreFoundationResources>)
333307

308+
add_swift_library(FoundationNetworking
309+
MODULE_NAME
310+
FoundationNetworking
311+
MODULE_LINK_NAME
312+
FoundationNetworking
313+
MODULE_PATH
314+
${CMAKE_CURRENT_BINARY_DIR}/swift/FoundationNetworking.swiftmodule
315+
SOURCES
316+
Foundation/Boxing.swift
317+
Foundation/NSURLRequest.swift
318+
Foundation/HTTPCookie.swift
319+
Foundation/HTTPCookieStorage.swift
320+
Foundation/URLAuthenticationChallenge.swift
321+
Foundation/URLCache.swift
322+
Foundation/URLCredential.swift
323+
Foundation/URLCredentialStorage.swift
324+
Foundation/URLProtectionSpace.swift
325+
Foundation/URLProtocol.swift
326+
Foundation/URLRequest.swift
327+
Foundation/URLResponse.swift
328+
Foundation/URLSession/BodySource.swift
329+
Foundation/URLSession/Configuration.swift
330+
Foundation/URLSession/http/HTTPMessage.swift
331+
Foundation/URLSession/http/HTTPURLProtocol.swift
332+
Foundation/URLSession/libcurl/EasyHandle.swift
333+
Foundation/URLSession/libcurl/libcurlHelpers.swift
334+
Foundation/URLSession/libcurl/MultiHandle.swift
335+
Foundation/URLSession/Message.swift
336+
Foundation/URLSession/NativeProtocol.swift
337+
Foundation/URLSession/NetworkingSpecific.swift
338+
Foundation/URLSession/ftp/FTPURLProtocol.swift
339+
Foundation/URLSession/TaskRegistry.swift
340+
Foundation/URLSession/TransferState.swift
341+
Foundation/URLSession/URLSession.swift
342+
Foundation/URLSession/URLSessionConfiguration.swift
343+
Foundation/URLSession/URLSessionDelegate.swift
344+
Foundation/URLSession/URLSessionTask.swift
345+
TARGET
346+
${CMAKE_C_COMPILER_TARGET}
347+
CFLAGS
348+
${MSVCRT_C_FLAGS}
349+
${deployment_target}
350+
${deployment_enable_libdispatch}
351+
-F${CMAKE_CURRENT_BINARY_DIR}
352+
LINK_FLAGS
353+
${MSVCRT_LINK_FLAGS}
354+
-L${CMAKE_CURRENT_BINARY_DIR}
355+
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY}
356+
${libdispatch_ldflags}
357+
-lFoundation
358+
${Foundation_INTERFACE_LIBRARIES}
359+
${CFURLSessionInterface_LIBRARIES}
360+
${CURL_LIBRARIES}
361+
${Foundation_RPATH}
362+
${WORKAROUND_SR9138}
363+
${WORKAROUND_SR9995}
364+
$<$<PLATFORM_ID:Windows>:$<TARGET_OBJECTS:CoreFoundationResources>>
365+
SWIFT_FLAGS
366+
-DDEPLOYMENT_RUNTIME_SWIFT
367+
-DNS_BUILDING_FOUNDATION_NETWORKING
368+
${deployment_enable_libdispatch}
369+
-I;${ICU_INCLUDE_DIR}
370+
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
371+
${libdispatch_cflags}
372+
${swift_enable_testing}
373+
${swift_optimization_flags}
374+
DEPENDS
375+
uuid
376+
CoreFoundation
377+
$<$<PLATFORM_ID:Windows>:CoreFoundationResources>
378+
Foundation)
379+
380+
381+
334382
if(NOT BUILD_SHARED_LIBS)
335383
set(Foundation_INTERFACE_LIBRARIES
336384
-L${install_dir}/usr/lib

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <CoreFoundation/CFXMLInterface.h>
2525
#include <CoreFoundation/CFRegularExpression.h>
2626
#include <CoreFoundation/CFLogUtilities.h>
27-
#include <CoreFoundation/CFURLSessionInterface.h>
2827
#include <CoreFoundation/CFDateIntervalFormatter.h>
2928
#include <CoreFoundation/ForFoundationOnly.h>
3029
#include <CoreFoundation/CFCharacterSetPriv.h>

0 commit comments

Comments
 (0)