-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
FoundationNetworking: Split networking into its own module #2289
Conversation
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.
@swift-ci please test |
CoreFoundation/CMakeLists.txt
Outdated
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) | ||
set_target_properties(CFURLSessionInterface | ||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't have CFCharacterSet mappings.
CMakeLists.txt
Outdated
${CMAKE_C_COMPILER_TARGET} | ||
CFLAGS | ||
${MSVCRT_C_FLAGS} | ||
${deployment_target} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should no longer be needed, deployment_target
has been removed in favour of TARGET_OS_*
from TargetConditionals.h
CMakeLists.txt
Outdated
CFLAGS | ||
${MSVCRT_C_FLAGS} | ||
${deployment_target} | ||
${deployment_enable_libdispatch} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that I have cleaned this up as well. This was previously needed as there was a mode for CoreFoundation
to be built without libdispatch which is no longer supported.
CMakeLists.txt
Outdated
${libdispatch_ldflags} | ||
-lFoundation | ||
${Foundation_INTERFACE_LIBRARIES} | ||
${CFURLSessionInterface_LIBRARIES} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems odd
CMakeLists.txt
Outdated
LINK_FLAGS | ||
${MSVCRT_LINK_FLAGS} | ||
-L${CMAKE_CURRENT_BINARY_DIR} | ||
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this part actually use ICU?
CMakeLists.txt
Outdated
${Foundation_RPATH} | ||
${WORKAROUND_SR9138} | ||
${WORKAROUND_SR9995} | ||
$<$<PLATFORM_ID:Windows>:$<TARGET_OBJECTS:CoreFoundationResources>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need the CoreFoundationResources? That is for the TimeZone information
CMakeLists.txt
Outdated
$<$<PLATFORM_ID:Windows>:$<TARGET_OBJECTS:CoreFoundationResources>> | ||
SWIFT_FLAGS | ||
-DDEPLOYMENT_RUNTIME_SWIFT | ||
-DNS_BUILDING_FOUNDATION_NETWORKING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems odd
CMakeLists.txt
Outdated
-DDEPLOYMENT_RUNTIME_SWIFT | ||
-DNS_BUILDING_FOUNDATION_NETWORKING | ||
${deployment_enable_libdispatch} | ||
-I;${ICU_INCLUDE_DIR} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need ICU here?
endif() | ||
|
||
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") | ||
target_compile_options(CoreFoundation | ||
PRIVATE | ||
-fblocks | ||
/EHsc) | ||
target_compile_options(CFURLSessionInterface |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
CoreFoundation/CMakeLists.txt
Outdated
endif() | ||
if(CMAKE_SYSTEM_NAME STREQUAL Android) | ||
target_link_libraries(CoreFoundation | ||
PRIVATE | ||
log) | ||
target_link_libraries(CFURLSessionInterface | ||
PRIVATE | ||
log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does CFURLSessionInterface
use the android log apis?
CoreFoundation/CMakeLists.txt
Outdated
endif() | ||
target_link_libraries(CoreFoundation | ||
PRIVATE | ||
Threads::Threads | ||
${CMAKE_DL_LIBS}) | ||
target_link_libraries(CFURLSessionInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does CFURLSessionInterface
use threads and dl*
functions?
if(CMAKE_SYSTEM_NAME STREQUAL Windows) | ||
target_link_libraries(CoreFoundation | ||
PRIVATE | ||
AdvAPI32 | ||
Secur32 | ||
User32 | ||
mincore) | ||
target_link_libraries(CFURLSessionInterface |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
CoreFoundation/CMakeLists.txt
Outdated
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) | ||
set_target_properties(CFURLSessionInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This re-embeds the character set data, why?
Collectively responding: I replicated the existing setup for CF line-for-line. Certain things are flat-out incorrect, like the character data; certain are not useful, like icu. I'll do a pass for all the objections. |
You are correct. Yay, sleep deprivation. Fixing. |
@compnerd I addressed everything that I could locally check would compile. |
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this seems good now.
CMakeLists.txt
Outdated
uuid | ||
CoreFoundation | ||
$<$<PLATFORM_ID:Windows>:CoreFoundationResources> | ||
Foundation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed it; I'll fix it before merge.
|
||
@available(*, unavailable, message: "This type has moved to the FoundationNetworking module. Import that module to use it.", | ||
renamed: "FoundationNetworking.CachedURLResponse") | ||
public typealias CachedURLResponse = AnyObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: these should not use renamed:
, because we want people to continue using the unqualified spelling to refer to them once they've imported FoundationNetworking. (That should still work without ambiguity because unavailable declarations should only be used if there's no valid available one.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're relying on the latter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I cannot mandate a spelling be qualified or not; it is my job to make both work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(but I agree we shouldn't be recommending to use the qualified one if possible.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'm specifically talking about renamed:
because that changes the error message and creates a fix-it.
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
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.: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 forURL
andURLComponents
) into a newFoundationNetworking
module (SwiftFoundationNetworking
on Darwin). Note: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 inFoundationNetworking
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 ofFoundationNetworking
.