Skip to content
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

Move CG symbols to CoreFoundation to match Darwin behavior #4922

Open
Kyle-Ye opened this issue Mar 10, 2024 · 0 comments
Open

Move CG symbols to CoreFoundation to match Darwin behavior #4922

Kyle-Ye opened this issue Mar 10, 2024 · 0 comments

Comments

@Kyle-Ye
Copy link
Collaborator

Kyle-Ye commented Mar 10, 2024

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

@Kyle-Ye Kyle-Ye changed the title Move CGFloat/CGSize/CGRect to CoreFoundation to match Darwin behavior Move CG symbols to CoreFoundation to match Darwin behavior Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant