swiftlang/swift-corelibs-foundation

Move CG symbols to CoreFoundation to match Darwin behavior

Opened this issue · 0 comments

Issue

On recent SDK of Darwin platform, Apple has moved the definition of many CG symbols(CGFloat CGSize CGRect) from CoreGraphic to CoreFoundation.

So when we use import CoreFoundation, we can use CGFloat on Darwin now. But it will require use to import the whole Foundation module on non-Darwin platform.

Also, to avoid source breaking change, we may apply some trick which Apple use on Darwin platform to avoid import struct CoreGraphics.CGFloat failing to build issue.

// Currently valid on Darwin platform with macOS 14/iOS 17 SDK
import struct CoreGraphics.CGFloat
import struct CoreFoundation.CGFloat

Background/Context

I have found it first in this discussion https://forums.swift.org/t/need-compiler-expert-is-there-a-way-to-workaround-symbol-not-found-crash-on-ios-15-sim-for-apis-available-since-ios-13/69527/17

And besides it I also facing some issue on my other project:
eg.

I used to use the following code before assuming CGXX is defined in CoreGraphics

#if canImport(Darwin)
import CoreGraphics
#else
import Foundation // swift-corelibs-foundation
#endif

Then after the transition of CGXX from CoreGraphics to CoreFoundation
I changed to use the following code

import Foundation

And assume I have a CKit which reexported CoreFoundation.
The following code compiles on Darwin platform but not on Linux nor WASM.

import CKit // or import CoreFoundation
let a: CGFloat = 0.0 // error: cannot find type 'CGFloat' in scope

Considering we will migrate to use swift-foundation later, I'm always try to avoid the direct dependency of Foundation here.
Would it be great if we can align the behavior on all platforms?

Other

https://forums.swift.org/t/move-cg-symbols-to-corefoundation-to-match-darwin-behavior/70554