diff --git a/Package.resolved b/Package.resolved index 6f044af8..89bce8d4 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "b56337b3dd1894393ef8978297a221dd102010b985af35ef055a726c560435e6", + "originHash" : "6ae2798ced7417c65233e0130814db449aa933d9f98ec74d935b06b494949ef9", "pins" : [ { "identity" : "opengraph", @@ -9,6 +9,15 @@ "branch" : "main", "revision" : "93e713f1357fc04ca917635d09460dbf42b663b6" } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } } ], "version" : 3 diff --git a/Package.swift b/Package.swift index 1afa4cf2..155e6629 100644 --- a/Package.swift +++ b/Package.swift @@ -68,11 +68,11 @@ default: } var sharedSwiftSettings: [SwiftSetting] = [ - .enableExperimentalFeature("AccessLevelOnImport"), + .enableUpcomingFeature("BareSlashRegexLiterals"), + // .enableUpcomingFeature("InternalImportsByDefault"), .define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"), .define("OPENSWIFTUI_RELEASE_\(releaseVersion)"), .swiftLanguageMode(.v5), - .enableUpcomingFeature("BareSlashRegexLiterals"), ] if releaseVersion >= 2021 { @@ -86,10 +86,13 @@ if warningsAsErrorsCondition { sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"])) } +// NOTE: +// In macOS: Mac Catalyst App will use macOS-varient build of SwiftUI.framework in /System/Library/Framework and iOS varient of SwiftUI.framework in /System/iOSSupport/System/Library/Framework +// Add `|| Mac Catalyst` check everywhere in `OpenSwiftUICore` and `OpenSwiftUI_SPI`. let openSwiftUICoreTarget = Target.target( name: "OpenSwiftUICore", dependencies: [ - "COpenSwiftUICore", + "OpenSwiftUI_SPI", .product(name: "OpenGraphShims", package: "OpenGraph"), ], swiftSettings: sharedSwiftSettings @@ -97,7 +100,6 @@ let openSwiftUICoreTarget = Target.target( let openSwiftUITarget = Target.target( name: "OpenSwiftUI", dependencies: [ - "COpenSwiftUI", "OpenSwiftUICore", .target(name: "CoreServices", condition: .when(platforms: [.iOS])), .product(name: "OpenGraphShims", package: "OpenGraph"), @@ -111,6 +113,17 @@ let openSwiftUIExtensionTarget = Target.target( ], swiftSettings: sharedSwiftSettings ) +let OpenSwiftUI_SPITestTarget = Target.testTarget( + name: "OpenSwiftUI_SPITests", + dependencies: [ + "OpenSwiftUI_SPI", + // For ProtocolDescriptor symbol linking + "OpenSwiftUI", + .product(name: "Numerics", package: "swift-numerics") + ], + exclude: ["README.md"], + swiftSettings: sharedSwiftSettings +) let openSwiftUICoreTestTarget = Target.testTarget( name: "OpenSwiftUICoreTests", dependencies: [ @@ -144,7 +157,10 @@ let package = Package( products: [ .library(name: "OpenSwiftUI", targets: ["OpenSwiftUI", "OpenSwiftUIExtension"]), // FIXME: This will block xcodebuild build(iOS CI) somehow - // .library(name: "COpenSwiftUI", targets: ["COpenSwiftUI"]), + // .library(name: "OpenSwiftUI_SPI", targets: ["OpenSwiftUI_SPI"]), + ], + dependencies: [ + .package(url: "https://github.com/apple/swift-numerics.git", from: "1.0.2"), ], targets: [ // TODO: Add SwiftGTK as an backend alternative for UIKit/AppKit on Linux and macOS @@ -157,18 +173,8 @@ let package = Package( ] ), .target( - name: "COpenSwiftUI", - dependencies: [ - "COpenSwiftUICore", - ], - cSettings: [ - .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), - .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), - .define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])), - ] - ), - .target( - name: "COpenSwiftUICore", + name: "OpenSwiftUI_SPI", + publicHeadersPath: ".", cSettings: [ .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), @@ -180,6 +186,7 @@ let package = Package( openSwiftUITarget, openSwiftUIExtensionTarget, + OpenSwiftUI_SPITestTarget, openSwiftUICoreTestTarget, openSwiftUITestTarget, openSwiftUICompatibilityTestTarget, @@ -227,6 +234,8 @@ extension Target { if attributeGraphCondition { openSwiftUICoreTarget.addAGSettings() openSwiftUITarget.addAGSettings() + + OpenSwiftUI_SPITestTarget.addAGSettings() openSwiftUICoreTestTarget.addAGSettings() openSwiftUITestTarget.addAGSettings() openSwiftUICompatibilityTestTarget.addAGSettings() diff --git a/Package@swift-5.10.swift b/Package@swift-5.10.swift index 8b1f1aef..b159df74 100644 --- a/Package@swift-5.10.swift +++ b/Package@swift-5.10.swift @@ -65,10 +65,11 @@ default: } var sharedSwiftSettings: [SwiftSetting] = [ + .enableUpcomingFeature("BareSlashRegexLiterals"), .enableExperimentalFeature("AccessLevelOnImport"), + // .enableUpcomingFeature("InternalImportsByDefault"), .define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"), .define("OPENSWIFTUI_RELEASE_\(releaseVersion)"), - .enableUpcomingFeature("BareSlashRegexLiterals"), ] if releaseVersion >= 2021 { @@ -85,7 +86,7 @@ if warningsAsErrorsCondition { let openSwiftUICoreTarget = Target.target( name: "OpenSwiftUICore", dependencies: [ - "COpenSwiftUICore", + "OpenSwiftUI_SPI", .product(name: "OpenGraphShims", package: "OpenGraph"), ], swiftSettings: sharedSwiftSettings @@ -93,7 +94,6 @@ let openSwiftUICoreTarget = Target.target( let openSwiftUITarget = Target.target( name: "OpenSwiftUI", dependencies: [ - "COpenSwiftUI", "OpenSwiftUICore", .target(name: "CoreServices", condition: .when(platforms: [.iOS])), .product(name: "OpenGraphShims", package: "OpenGraph"), @@ -140,7 +140,7 @@ let package = Package( products: [ .library(name: "OpenSwiftUI", targets: ["OpenSwiftUI", "OpenSwiftUIExtension"]), // FIXME: This will block xcodebuild build(iOS CI) somehow - // .library(name: "COpenSwiftUI", targets: ["COpenSwiftUI"]), + // .library(name: "OpenSwiftUI_SPI", targets: ["OpenSwiftUI_SPI"]), ], targets: [ // TODO: Add SwiftGTK as an backend alternative for UIKit/AppKit on Linux and macOS @@ -153,18 +153,8 @@ let package = Package( ] ), .target( - name: "COpenSwiftUI", - dependencies: [ - "COpenSwiftUICore", - ], - cSettings: [ - .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), - .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), - .define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])), - ] - ), - .target( - name: "COpenSwiftUICore", + name: "OpenSwiftUI_SPI", + publicHeadersPath: ".", cSettings: [ .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), diff --git a/Sources/COpenSwiftUI/empty.c b/Sources/COpenSwiftUI/empty.c deleted file mode 100644 index 8b137891..00000000 --- a/Sources/COpenSwiftUI/empty.c +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Sources/COpenSwiftUI/include/empty.h b/Sources/COpenSwiftUI/include/empty.h deleted file mode 100644 index 8b137891..00000000 --- a/Sources/COpenSwiftUI/include/empty.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Sources/COpenSwiftUICore/Shims/CoreFoundation_Private.c b/Sources/COpenSwiftUICore/Shims/CoreFoundation_Private.c deleted file mode 100644 index 4c61b5e1..00000000 --- a/Sources/COpenSwiftUICore/Shims/CoreFoundation_Private.c +++ /dev/null @@ -1,16 +0,0 @@ -// -// CoreFoundation_Private.c -// COpenSwiftUI - -#include "CoreFoundation_Private.h" -#include "dyld_Private.h" - -#if !OPENSWIFTUI_TARGET_OS_DARWIN - -#define PLATFORM_IOS 2 -#define PLATFORM_MACCATALYST 6 - -bool _CFMZEnabled(void) { - return dyld_get_active_platform() == PLATFORM_MACCATALYST || dyld_get_active_platform() == PLATFORM_IOS; -} -#endif diff --git a/Sources/COpenSwiftUICore/include/dyld_Private.h b/Sources/COpenSwiftUICore/include/dyld_Private.h deleted file mode 100644 index 4e039ab2..00000000 --- a/Sources/COpenSwiftUICore/include/dyld_Private.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// dyld_Private.h -// OpenSwiftUI -// -// Audited for RELEASE_2021 -// Status: Complete - -#ifndef dyld_Private_h -#define dyld_Private_h - -#include "OpenSwiftUIBase.h" - -typedef uint32_t dyld_platform_t; - -typedef struct { - dyld_platform_t platform; - uint32_t version; -} dyld_build_version_t; - -// Always return true on non-Darwin platform -OPENSWIFTUI_EXPORT -bool dyld_program_sdk_at_least(dyld_build_version_t version); - -OPENSWIFTUI_EXPORT -dyld_platform_t dyld_get_active_platform(void); - -#endif /* dyld_Private_h */ diff --git a/Sources/OpenSwiftUI/Integration/UIKit/UIGraphicsView.swift b/Sources/OpenSwiftUI/Integration/UIKit/UIGraphicsView.swift index 7d5e51b0..07830ac1 100644 --- a/Sources/OpenSwiftUI/Integration/UIKit/UIGraphicsView.swift +++ b/Sources/OpenSwiftUI/Integration/UIKit/UIGraphicsView.swift @@ -6,7 +6,7 @@ // Status: Complete #if os(iOS) -internal import COpenSwiftUI +internal import OpenSwiftUI_SPI import UIKit class _UIGraphicsView: UIView { diff --git a/Sources/OpenSwiftUI/Test/_PerformanceTest.swift b/Sources/OpenSwiftUI/Test/_PerformanceTest.swift index dc341f43..0d791caf 100644 --- a/Sources/OpenSwiftUI/Test/_PerformanceTest.swift +++ b/Sources/OpenSwiftUI/Test/_PerformanceTest.swift @@ -11,7 +11,7 @@ import UIKit import AppKit #endif -internal import COpenSwiftUI +internal import OpenSwiftUI_SPI public protocol _PerformanceTest: _Test { var name: String { get } diff --git a/Sources/OpenSwiftUI/View/Control/Button/ButtonStyle/ButtonDefaultRenderingModeModifier.swift b/Sources/OpenSwiftUI/View/Control/Button/ButtonStyle/ButtonDefaultRenderingModeModifier.swift index b68b5871..08ab1f9a 100644 --- a/Sources/OpenSwiftUI/View/Control/Button/ButtonStyle/ButtonDefaultRenderingModeModifier.swift +++ b/Sources/OpenSwiftUI/View/Control/Button/ButtonStyle/ButtonDefaultRenderingModeModifier.swift @@ -6,7 +6,7 @@ // Status: Complete // ID: 6C985860B64B768EC9A2691B5DBA71A0 -internal import COpenSwiftUI +internal import OpenSwiftUI_SPI extension View { func buttonDefaultRenderingMode() -> some View { diff --git a/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift b/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift index ef740343..e9139e19 100644 --- a/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift +++ b/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift @@ -8,7 +8,7 @@ #if canImport(Darwin) #if os(iOS) || os(tvOS) import UIKit -#if os(iOS) +#if os(iOS) && !targetEnvironment(macCatalyst) private import CoreServices #endif #elseif os(macOS) @@ -37,7 +37,7 @@ struct OpenSensitiveURLActionKey: EnvironmentKey { static let defaultValue = OpenURLAction( handler: .system { url, completion in - #if os(iOS) + #if os(iOS) && !targetEnvironment(macCatalyst) let config = _LSOpenConfiguration() config.isSensitive = true let selector = Selector(("_currentOpenApplicationEndpoint")) diff --git a/Sources/OpenSwiftUICore/Data/Other/2021/LockedPointer.swift b/Sources/OpenSwiftUICore/Data/Other/2021/LockedPointer.swift index 3c27524a..0dfa9caa 100644 --- a/Sources/OpenSwiftUICore/Data/Other/2021/LockedPointer.swift +++ b/Sources/OpenSwiftUICore/Data/Other/2021/LockedPointer.swift @@ -7,7 +7,7 @@ #if OPENSWIFTUI_RELEASE_2021 -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI package extension LockedPointer { @_transparent diff --git a/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeAtomicLazy.swift b/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeAtomicLazy.swift index c1d8f1f4..b3775317 100644 --- a/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeAtomicLazy.swift +++ b/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeAtomicLazy.swift @@ -7,7 +7,7 @@ #if OPENSWIFTUI_RELEASE_2021 -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI package struct UnsafeAtomicLazy: Destroyable { @UnsafeLockedPointer diff --git a/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeLockedPointer.swift b/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeLockedPointer.swift index 1c63a50e..df481986 100644 --- a/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeLockedPointer.swift +++ b/Sources/OpenSwiftUICore/Data/Other/2021/UnsafeLockedPointer.swift @@ -7,7 +7,7 @@ #if OPENSWIFTUI_RELEASE_2021 -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI @propertyWrapper package struct UnsafeLockedPointer: Destroyable { diff --git a/Sources/OpenSwiftUICore/Data/Property/PropertyList.swift b/Sources/OpenSwiftUICore/Data/Property/PropertyList.swift index d77f2608..3f16ce15 100644 --- a/Sources/OpenSwiftUICore/Data/Property/PropertyList.swift +++ b/Sources/OpenSwiftUICore/Data/Property/PropertyList.swift @@ -7,7 +7,7 @@ // ID: 2B32D570B0B3D2A55DA9D4BFC1584D20 (RELEASE_2021) // ID: D64CE6C88E7413721C59A34C0C940F2C (RELEASE_2024) -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI internal import OpenGraphShims // MARK: - PropertyList diff --git a/Sources/OpenSwiftUICore/Data/State/ObservableObjectLocation.swift b/Sources/OpenSwiftUICore/Data/State/ObservableObjectLocation.swift index 347fff37..66b589a6 100644 --- a/Sources/OpenSwiftUICore/Data/State/ObservableObjectLocation.swift +++ b/Sources/OpenSwiftUICore/Data/State/ObservableObjectLocation.swift @@ -10,7 +10,7 @@ import OpenCombine #else import Combine #endif -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI struct ObservableObjectLocation: Location where Root: ObservableObject { let base: Root diff --git a/Sources/OpenSwiftUICore/Data/State/StoredLocation.swift b/Sources/OpenSwiftUICore/Data/State/StoredLocation.swift index a7b12a01..ce3b8c00 100644 --- a/Sources/OpenSwiftUICore/Data/State/StoredLocation.swift +++ b/Sources/OpenSwiftUICore/Data/State/StoredLocation.swift @@ -8,7 +8,7 @@ // ID: 4F21368B1C1680817451AC25B55A8D48 (RELEASE_2024) internal import OpenGraphShims -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI package class StoredLocationBase: AnyLocation, Location, @unchecked Sendable { private struct Data { diff --git a/Sources/OpenSwiftUICore/Data/Transaction/Transaction.swift b/Sources/OpenSwiftUICore/Data/Transaction/Transaction.swift index 7f6488de..6b921d9f 100644 --- a/Sources/OpenSwiftUICore/Data/Transaction/Transaction.swift +++ b/Sources/OpenSwiftUICore/Data/Transaction/Transaction.swift @@ -7,7 +7,7 @@ // ID: B2543BCA257433E04979186A1DC2B6BC internal import OpenGraphShims -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI /// The context of the current state-processing update. /// diff --git a/Sources/OpenSwiftUICore/Data/Update.swift b/Sources/OpenSwiftUICore/Data/Update.swift index 072d398f..c51de9fc 100644 --- a/Sources/OpenSwiftUICore/Data/Update.swift +++ b/Sources/OpenSwiftUICore/Data/Update.swift @@ -7,7 +7,7 @@ // ID: EA173074DA35FA471DC70643259B7E74 (RELEASE_2021) // ID: 61534957AEEC2EDC447ABDC13B4D426F (RELEASE_2024) -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI internal import OpenGraphShims import Foundation diff --git a/Sources/OpenSwiftUICore/EventHandling/InputEvent/HitTesting/ContentResponder.swift b/Sources/OpenSwiftUICore/EventHandling/InputEvent/HitTesting/ContentResponder.swift index c3e03ab6..c9d6c535 100644 --- a/Sources/OpenSwiftUICore/EventHandling/InputEvent/HitTesting/ContentResponder.swift +++ b/Sources/OpenSwiftUICore/EventHandling/InputEvent/HitTesting/ContentResponder.swift @@ -6,7 +6,7 @@ // Status: WIP import Foundation -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI protocol ContentResponder { func contains(points: [CGPoint], size: CGSize) -> BitVector64 diff --git a/Sources/OpenSwiftUICore/Graph/GraphHost.swift b/Sources/OpenSwiftUICore/Graph/GraphHost.swift index d5d98f9c..8ef91914 100644 --- a/Sources/OpenSwiftUICore/Graph/GraphHost.swift +++ b/Sources/OpenSwiftUICore/Graph/GraphHost.swift @@ -7,7 +7,7 @@ // ID: 30C09FF16BC95EC5173809B57186CAC3 (RELEASE_2021) // ID: F9F204BD2F8DB167A76F17F3FB1B3335 (RELEASE_2024) -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI package import OpenGraphShims import Foundation diff --git a/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift b/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift index 3067142a..7a19ff29 100644 --- a/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift +++ b/Sources/OpenSwiftUICore/Graphic/Color/ColorResolved.swift @@ -6,7 +6,7 @@ // Status: WIP import Foundation -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI // MARK: - Color.Resolved @@ -322,7 +322,7 @@ extension Color.Resolved { var green: CGFloat = 0 var blue: CGFloat = 0 var alpha: CGFloat = 0 - let result = CoreColorPlatformColorGetComponents(isAppKitBased(), platformColor, &red, &green, &blue, &alpha) + let result = OpenSwiftUICoreColorPlatformColorGetComponents(isAppKitBased(), platformColor, &red, &green, &blue, &alpha) if result { self.init(red: Float(red), green: Float(green), blue: Float(blue), opacity: Float(alpha)) } else { @@ -332,7 +332,7 @@ extension Color.Resolved { // ID: 4330A474F53D66045762501ED6F8A749 private static let cache: ObjectCache = ObjectCache { resolved in - CoreColor.platformColor(resolvedColor: resolved)! + OpenSwiftUICoreColor.platformColor(resolvedColor: resolved)! } package var kitColor: NSObject { diff --git a/Sources/OpenSwiftUICore/Graphic/Color/CoreColor+Extension.swift b/Sources/OpenSwiftUICore/Graphic/Color/CoreColor+Extension.swift index 1d7a242d..5101f069 100644 --- a/Sources/OpenSwiftUICore/Graphic/Color/CoreColor+Extension.swift +++ b/Sources/OpenSwiftUICore/Graphic/Color/CoreColor+Extension.swift @@ -1,76 +1,22 @@ // // CoreColor+Extension.swift -// OpenSwiftUI +// OpenSwiftUICore // // Audited for RELEASE_2024 // Status: Complete #if canImport(Darwin) import Foundation -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI -extension CoreColor { +extension OpenSwiftUICoreColor { package static func platformColor(resolvedColor: Color.Resolved) -> NSObject? { platformColor(red: CGFloat(resolvedColor.red), green: CGFloat(resolvedColor.green), blue: CGFloat(resolvedColor.blue), alpha: CGFloat(resolvedColor.opacity)) } package static func platformColor(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> NSObject? { - CorePlatformColorForRGBA(isAppKitBased(), red, green, blue, alpha) + OpenSwiftUICorePlatformColorForRGBA(isAppKitBased(), red, green, blue, alpha) } - - #if os(iOS) - static var systemRed: NSObject? { - systemRedColor(withSystem: isAppKitBased()) - } - - static var systemOrange: NSObject? { - systemOrangeColor(withSystem: isAppKitBased()) - } - - static var systemYellow: NSObject? { - systemYellowColor(withSystem: isAppKitBased()) - } - - static var systemGreen: NSObject? { - systemGreenColor(withSystem: isAppKitBased()) - } - - static var systemTeal: NSObject? { - systemTealColor(withSystem: isAppKitBased()) - } - - static var systemMint: NSObject? { - systemMintColor(withSystem: isAppKitBased()) - } - - static var systemCyan: NSObject? { - systemCyanColor(withSystem: isAppKitBased()) - } - - static var systemBlue: NSObject? { - systemBlueColor(withSystem: isAppKitBased()) - } - - static var systemIndigo: NSObject? { - systemIndigoColor(withSystem: isAppKitBased()) - } - - static var systemPurple: NSObject? { - systemPurpleColor(withSystem: isAppKitBased()) - } - - static var systemPink: NSObject? { - systemPinkColor(withSystem: isAppKitBased()) - } - - static var systemBrown: NSObject? { - systemBrownColor(withSystem: isAppKitBased()) - } - - static var systemGray: NSObject? { - systemGrayColor(withSystem: isAppKitBased()) - } - #endif } #endif diff --git a/Sources/OpenSwiftUICore/Log/Signpost.swift b/Sources/OpenSwiftUICore/Log/Signpost.swift index 2c531c12..fe83d7c6 100644 --- a/Sources/OpenSwiftUICore/Log/Signpost.swift +++ b/Sources/OpenSwiftUICore/Log/Signpost.swift @@ -7,7 +7,7 @@ // ID: 34756F646CF7AC3DBE2A8E0B344C962F (RELEASE_2021) // ID: 59349949219F590F26B6A55CEC9D59A2 (RELEASE_2024) -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI internal import OpenGraphShims #if canImport(Darwin) import os.signpost diff --git a/Sources/OpenSwiftUICore/Render/PlatformViewDefinition.swift b/Sources/OpenSwiftUICore/Render/PlatformViewDefinition.swift index 326367d0..77595c0f 100644 --- a/Sources/OpenSwiftUICore/Render/PlatformViewDefinition.swift +++ b/Sources/OpenSwiftUICore/Render/PlatformViewDefinition.swift @@ -5,7 +5,7 @@ // Audited for RELEASE_2024 // Status: Blocked by PlatformDrawable and GraphicsContext -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI #if canImport(Darwin) import QuartzCore #endif diff --git a/Sources/OpenSwiftUICore/Runtime/ProtocolDescriptor.swift b/Sources/OpenSwiftUICore/Runtime/ProtocolDescriptor.swift index db647d9a..189b9da6 100644 --- a/Sources/OpenSwiftUICore/Runtime/ProtocolDescriptor.swift +++ b/Sources/OpenSwiftUICore/Runtime/ProtocolDescriptor.swift @@ -5,7 +5,7 @@ // Audited for RELEASE_2021 // Status: WIP -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI internal import OpenGraphShims // MARK: - ProtocolDescriptor diff --git a/Sources/OpenSwiftUICore/Semantic/SemanticFeature.swift b/Sources/OpenSwiftUICore/Semantic/SemanticFeature.swift index 8636b524..49b0e5d0 100644 --- a/Sources/OpenSwiftUICore/Semantic/SemanticFeature.swift +++ b/Sources/OpenSwiftUICore/Semantic/SemanticFeature.swift @@ -5,7 +5,7 @@ // Audited for RELEASE_2024 // Status: Complete -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI package protocol SemanticFeature: Feature { static var introduced: Semantics { get } diff --git a/Sources/OpenSwiftUICore/Semantic/Semantics.swift b/Sources/OpenSwiftUICore/Semantic/Semantics.swift index 128eae83..8aed11c7 100644 --- a/Sources/OpenSwiftUICore/Semantic/Semantics.swift +++ b/Sources/OpenSwiftUICore/Semantic/Semantics.swift @@ -5,7 +5,7 @@ // Audited for RELEASE_2024 // Status: Complete -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI @inline(__always) package func isLinkedOnOrAfter(_ semantics: Semantics) -> Bool { diff --git a/Sources/OpenSwiftUICore/Shape/Path/Path.swift b/Sources/OpenSwiftUICore/Shape/Path/Path.swift index 63414bb7..f699d849 100644 --- a/Sources/OpenSwiftUICore/Shape/Path/Path.swift +++ b/Sources/OpenSwiftUICore/Shape/Path/Path.swift @@ -10,7 +10,7 @@ import Foundation #if canImport(CoreGraphics) -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI import CoreGraphics @_silgen_name("__CGPathParseString") diff --git a/Sources/OpenSwiftUICore/Util/Tracing.swift b/Sources/OpenSwiftUICore/Util/Tracing.swift index 7e71fd52..a5b9d299 100644 --- a/Sources/OpenSwiftUICore/Util/Tracing.swift +++ b/Sources/OpenSwiftUICore/Util/Tracing.swift @@ -18,7 +18,7 @@ import WASILibc #endif internal import OpenGraphShims import Foundation -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI #if canImport(Darwin) import os.log #endif diff --git a/Sources/OpenSwiftUICore/Util/Utils.swift b/Sources/OpenSwiftUICore/Util/Utils.swift index 69d2e30a..c3cef0ec 100644 --- a/Sources/OpenSwiftUICore/Util/Utils.swift +++ b/Sources/OpenSwiftUICore/Util/Utils.swift @@ -5,7 +5,7 @@ // Audited for RELEASE_2024 // Status: WIP -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI @inlinable @inline(__always) @@ -15,12 +15,13 @@ func asOptional(_ value: Value) -> Value? { return optionalValue } +#if canImport(Darwin) + +// NOTE: use runtime check instead of #if targetEnvironment(macCatalyst) +// Because Mac Catalyst will use macOS-varient build of OpenSwiftUICore.framework and Mac Catalyst/UIKitForMac varient of OpenSwiftUI.framework @inline(__always) package func isCatalyst() -> Bool { - #if os(iOS) || os(tvOS) || os(watchOS) - false - #elseif os(macOS) - // NOTE: use runtime check instead of #if targetEnvironment(macCatalyst) here + #if os(macOS) || targetEnvironment(macCatalyst) _CFMZEnabled() #else false @@ -29,22 +30,20 @@ package func isCatalyst() -> Bool { @inline(__always) package func isUIKitBased() -> Bool { - #if os(iOS) || os(tvOS) || os(watchOS) - true - #elseif os(macOS) + #if os(macOS) || targetEnvironment(macCatalyst) _CFMZEnabled() #else - false + true #endif } @inline(__always) package func isAppKitBased() -> Bool { - #if os(iOS) || os(tvOS) || os(watchOS) - false - #elseif os(macOS) + #if os(macOS) || targetEnvironment(macCatalyst) !_CFMZEnabled() #else false #endif } + +#endif diff --git a/Sources/OpenSwiftUICore/View/AnyView.swift b/Sources/OpenSwiftUICore/View/AnyView.swift index 18a661f5..32b659ef 100644 --- a/Sources/OpenSwiftUICore/View/AnyView.swift +++ b/Sources/OpenSwiftUICore/View/AnyView.swift @@ -7,7 +7,7 @@ // ID: A96961F3546506F21D8995C6092F15B5 internal import OpenGraphShims -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI @frozen public struct AnyView: PrimitiveView { diff --git a/Sources/OpenSwiftUICore/View/Debug/ViewDebug.swift b/Sources/OpenSwiftUICore/View/Debug/ViewDebug.swift index b6585bc4..445a3d80 100644 --- a/Sources/OpenSwiftUICore/View/Debug/ViewDebug.swift +++ b/Sources/OpenSwiftUICore/View/Debug/ViewDebug.swift @@ -7,7 +7,7 @@ import Foundation internal import OpenGraphShims -internal import COpenSwiftUICore +internal import OpenSwiftUI_SPI public enum _ViewDebug { public enum Property: UInt32, Hashable { diff --git a/Sources/COpenSwiftUICore/include/OpenSwiftUIBase.h b/Sources/OpenSwiftUI_SPI/OpenSwiftUIBase.h similarity index 100% rename from Sources/COpenSwiftUICore/include/OpenSwiftUIBase.h rename to Sources/OpenSwiftUI_SPI/OpenSwiftUIBase.h diff --git a/Sources/COpenSwiftUICore/include/OpenSwiftUITargetConditionals.h b/Sources/OpenSwiftUI_SPI/OpenSwiftUITargetConditionals.h similarity index 99% rename from Sources/COpenSwiftUICore/include/OpenSwiftUITargetConditionals.h rename to Sources/OpenSwiftUI_SPI/OpenSwiftUITargetConditionals.h index 84a6fb27..91a9a231 100644 --- a/Sources/COpenSwiftUICore/include/OpenSwiftUITargetConditionals.h +++ b/Sources/OpenSwiftUI_SPI/OpenSwiftUITargetConditionals.h @@ -145,12 +145,14 @@ #define OPENSWIFTUI_TARGET_OS_IOS TARGET_OS_IOS #define OPENSWIFTUI_TARGET_OS_WATCH TARGET_OS_WATCH #define OPENSWIFTUI_TARGET_OS_TV TARGET_OS_TV +#define OPENSWIFTUI_TARGET_OS_MACCATALYST TARGET_OS_MACCATALYST #else // iOS, watchOS, and tvOS are not supported #define OPENSWIFTUI_TARGET_OS_IPHONE 0 #define OPENSWIFTUI_TARGET_OS_IOS 0 #define OPENSWIFTUI_TARGET_OS_WATCH 0 #define OPENSWIFTUI_TARGET_OS_TV 0 +#define OPENSWIFTUI_TARGET_OS_MACCATALYST 0 #endif /* OpenSwiftUI Addition End */ diff --git a/Sources/COpenSwiftUICore/include/CoreColor.h b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreColor.h similarity index 71% rename from Sources/COpenSwiftUICore/include/CoreColor.h rename to Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreColor.h index 9a319ef3..f10b2a92 100644 --- a/Sources/COpenSwiftUICore/include/CoreColor.h +++ b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreColor.h @@ -1,11 +1,12 @@ // -// CoreColor.h -// COpenSwiftUI +// OpenSwiftUICoreColor.h +// OpenSwiftUI_SPI +// // Audited for RELEASE_2024 // Status: Complete -#ifndef CoreColor_h -#define CoreColor_h +#ifndef OpenSwiftUICoreColor_h +#define OpenSwiftUICoreColor_h #include "OpenSwiftUIBase.h" @@ -20,15 +21,15 @@ OPENSWIFTUI_ASSUME_NONNULL_BEGIN OPENSWIFTUI_EXPORT -BOOL CoreColorPlatformColorGetComponents(BOOL system, id color, CGFloat *red, CGFloat *green, CGFloat *blue, CGFloat *alpha); +BOOL OpenSwiftUICoreColorPlatformColorGetComponents(BOOL system, id color, CGFloat *red, CGFloat *green, CGFloat *blue, CGFloat *alpha); OPENSWIFTUI_EXPORT -NSObject * _Nullable CorePlatformColorForRGBA(BOOL system, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); +NSObject * _Nullable OpenSwiftUICorePlatformColorForRGBA(BOOL system, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); OPENSWIFTUI_EXPORT -Class CoreColorGetKitColorClass(BOOL system); +Class _Nullable OpenSwiftUICoreColorGetKitColorClass(BOOL system); -@interface CoreColor : NSObject +@interface OpenSwiftUICoreColor : NSObject + (nullable NSObject *)colorWithSystem:(BOOL)system cgColor: (CGColorRef)cgColor; + (nullable NSObject *)blackColorWithSystem:(BOOL)system; @@ -51,7 +52,7 @@ Class CoreColorGetKitColorClass(BOOL system); - (void)setFill; - (void)setStroke; - (CGColorRef)CGColor; -- (CoreColor *)colorWithAlphaComponent:(CGFloat)alpha; +- (OpenSwiftUICoreColor *)colorWithAlphaComponent:(CGFloat)alpha; @end @@ -59,4 +60,4 @@ OPENSWIFTUI_ASSUME_NONNULL_END #endif -#endif /* CoreColor_h */ +#endif /* OpenSwiftUICoreColor_h */ diff --git a/Sources/COpenSwiftUICore/Overlay/CoreGraphics/CoreColor.m b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreColor.m similarity index 61% rename from Sources/COpenSwiftUICore/Overlay/CoreGraphics/CoreColor.m rename to Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreColor.m index 1b42bf3f..fbd538a7 100644 --- a/Sources/COpenSwiftUICore/Overlay/CoreGraphics/CoreColor.m +++ b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreColor.m @@ -1,26 +1,24 @@ // -// CoreColor.h -// COpenSwiftUI +// OpenSwiftUICoreColor.h +// OpenSwiftUI_SPI +// // Audited for RELEASE_2024 // Status: Complete -#include "CoreColor.h" +#include "OpenSwiftUICoreColor.h" #if OPENSWIFTUI_TARGET_OS_DARWIN -#include "CoreGraphicsContext.h" +#include "OpenSwiftUICoreGraphicsContext.h" -Class CoreColorClass(BOOL isAppKitBased); +Class OpenSwiftUICoreColorClass(BOOL system); #if OPENSWIFTUI_TARGET_OS_OSX id NSColorSpaceForCGColorSpace(CGColorSpaceRef cgColorSpace); Class NSColorSpaceClass(void); #endif -BOOL CoreColorPlatformColorGetComponents(BOOL system, id color, CGFloat *red, CGFloat *green, CGFloat *blue, CGFloat *alpha) { - if (!color) { - return NO; - } - Class colorClass = CoreColorClass(system); +BOOL OpenSwiftUICoreColorPlatformColorGetComponents(BOOL system, id color, CGFloat *red, CGFloat *green, CGFloat *blue, CGFloat *alpha) { + Class colorClass = OpenSwiftUICoreColorClass(system); if (!colorClass) { return NO; } @@ -34,14 +32,20 @@ BOOL CoreColorPlatformColorGetComponents(BOOL system, id color, CGFloat *red, CG } else { return NO; } + } else { + // For OPENSWIFTUI_TARGET_OS_MACCATALYST + typedef BOOL (*Func)(id, SEL, CGFloat *, CGFloat *, CGFloat *, CGFloat *); + IMP imp = [color methodForSelector:@selector(getRed:green:blue:alpha:)]; + Func func = (Func)imp; + return func(color, @selector(getRed:green:blue:alpha:), red, green, blue, alpha); } + #else + return [color getRed:red green:green blue:blue alpha:alpha]; #endif - // NOTE: Fix Mac Catalyst selector type issue - return ((BOOL (*)(id, SEL))[color methodForSelector:@selector(getRed:green:blue:alpha:)])(color, @selector(getRed:green:blue:alpha:)); } -NSObject *CorePlatformColorForRGBA(BOOL system, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) { - Class colorClass = CoreColorClass(system); +NSObject *OpenSwiftUICorePlatformColorForRGBA(BOOL system, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) { + Class colorClass = OpenSwiftUICoreColorClass(system); if (!colorClass) { return nil; } @@ -49,29 +53,39 @@ BOOL CoreColorPlatformColorGetComponents(BOOL system, id color, CGFloat *red, CG if (system) { id colorSpace = NSColorSpaceForCGColorSpace(CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB)); return [colorClass colorWithColorSpace:colorSpace components:(CGFloat[]){red, green, blue, alpha} count:4]; + } else { + return [[colorClass alloc] initWithRed:red green:green blue:blue alpha:alpha]; } - #endif + #else return [[colorClass alloc] initWithRed:red green:green blue:blue alpha:alpha]; + #endif } -Class CoreColorGetKitColorClass(BOOL system) { - CoreColorClass(system); +Class _Nullable OpenSwiftUICoreColorGetKitColorClass(BOOL system) { + return OpenSwiftUICoreColorClass(system); } -Class CoreColorClass(BOOL system) { - static BOOL isValid = false; +Class _Nullable OpenSwiftUICoreColorClass(BOOL system) { + static BOOL isValid = true; static Class colorClass; static dispatch_once_t once; dispatch_once(&once, ^{ - if (system) { - Class class = NSClassFromString(@"NSColor"); + #if OPENSWIFTUI_TARGET_OS_OSX + if (!system) { + Class class = NSClassFromString(@"UIColor"); colorClass = class; isValid = class != nil; - } else { - Class class = NSClassFromString(@"UIColor"); + } + if (system) { + Class class = NSClassFromString(@"NSColor"); colorClass = class; isValid = class != nil; } + #else + Class class = NSClassFromString(@"UIColor"); + colorClass = class; + isValid = class != nil; + #endif }); if (isValid) { return colorClass; @@ -101,89 +115,89 @@ Class NSColorSpaceClass(void) { } #endif -@interface CoreColor () { +@interface OpenSwiftUICoreColor () { CGColorRef _color; } @end -@implementation CoreColor +@implementation OpenSwiftUICoreColor + (NSObject *)colorWithSystem:(BOOL)system cgColor: (CGColorRef)cgColor { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); if (colorClass) { return [colorClass colorWithCGColor: cgColor]; } else { - return [[CoreColor alloc] initWithCGColor: cgColor]; + return [[OpenSwiftUICoreColor alloc] initWithCGColor: cgColor]; } } + (NSObject *)blackColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass blackColor]; } + (NSObject *)systemRedColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemRedColor]; } + (NSObject *)systemOrangeColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemOrangeColor]; } + (NSObject *)systemYellowColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemYellowColor]; } + (NSObject *)systemGreenColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemGreenColor]; } + (NSObject *)systemTealColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemTealColor]; } + (NSObject *)systemMintColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemMintColor]; } + (NSObject *)systemCyanColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemCyanColor]; } + (NSObject *)systemBlueColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemBlueColor]; } + (NSObject *)systemIndigoColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemIndigoColor]; } + (NSObject *)systemPurpleColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemPurpleColor]; } + (NSObject *)systemPinkColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemPinkColor]; } + (NSObject *)systemBrownColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemBrownColor]; } + (NSObject *)systemGrayColorWithSystem:(BOOL)system { - Class colorClass = CoreColorClass(system); + Class colorClass = OpenSwiftUICoreColorClass(system); return [colorClass systemGrayColor]; } @@ -199,7 +213,7 @@ - (void)dealloc { } - (void)set { - CGContextRef context = CoreGraphicsContext.current.CGContext; + CGContextRef context = OpenSwiftUICoreGraphicsContext.current.CGContext; if (!context) { return; } @@ -208,7 +222,7 @@ - (void)set { } - (void)setFill { - CGContextRef context = CoreGraphicsContext.current.CGContext; + CGContextRef context = OpenSwiftUICoreGraphicsContext.current.CGContext; if (!context) { return; } @@ -216,7 +230,7 @@ - (void)setFill { } - (void)setStroke { - CGContextRef context = CoreGraphicsContext.current.CGContext; + CGContextRef context = OpenSwiftUICoreGraphicsContext.current.CGContext; if (!context) { return; } @@ -227,9 +241,9 @@ - (CGColorRef)CGColor { return _color; } -- (CoreColor *)colorWithAlphaComponent:(CGFloat)alpha { +- (OpenSwiftUICoreColor *)colorWithAlphaComponent:(CGFloat)alpha { CGColorRef newColor = CGColorCreateCopyWithAlpha(_color, alpha); - CoreColor *color = [[CoreColor alloc] initWithCGColor:newColor]; + OpenSwiftUICoreColor *color = [[OpenSwiftUICoreColor alloc] initWithCGColor:newColor]; CGColorRelease(newColor); return color; } diff --git a/Sources/COpenSwiftUICore/include/CoreGraphicsContext.h b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.h similarity index 54% rename from Sources/COpenSwiftUICore/include/CoreGraphicsContext.h rename to Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.h index 2cd1a602..cb232540 100644 --- a/Sources/COpenSwiftUICore/include/CoreGraphicsContext.h +++ b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.h @@ -1,11 +1,12 @@ // -// CoreGraphicsContext.h -// COpenSwiftUI +// OpenSwiftUICoreGraphicsContext.h +// OpenSwiftUI_SPI +// // Audited for RELEASE_2024 // Status: Complete -#ifndef CoreGraphicsContext_h -#define CoreGraphicsContext_h +#ifndef OpenSwiftUICoreGraphicsContext_h +#define OpenSwiftUICoreGraphicsContext_h #include "OpenSwiftUIBase.h" @@ -15,9 +16,9 @@ OPENSWIFTUI_ASSUME_NONNULL_BEGIN -@interface CoreGraphicsContext : NSObject +@interface OpenSwiftUICoreGraphicsContext : NSObject -@property (class, nonatomic, readonly) CoreGraphicsContext *current; +@property (class, nonatomic, readonly) OpenSwiftUICoreGraphicsContext *current; @property (nonatomic, readonly) CGContextRef CGContext; - (instancetype)initWithCGContext:(CGContextRef)ctx; @@ -30,4 +31,4 @@ OPENSWIFTUI_ASSUME_NONNULL_END #endif -#endif /* CoreGraphicsContext_h */ +#endif /* OpenSwiftUICoreGraphicsContext_h */ diff --git a/Sources/COpenSwiftUICore/Overlay/CoreGraphics/CoreGraphicsContext.m b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.m similarity index 71% rename from Sources/COpenSwiftUICore/Overlay/CoreGraphics/CoreGraphicsContext.m rename to Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.m index 604d3c00..849295cb 100644 --- a/Sources/COpenSwiftUICore/Overlay/CoreGraphics/CoreGraphicsContext.m +++ b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.m @@ -1,27 +1,28 @@ // -// CoreColor.h -// COpenSwiftUI +// OpenSwiftUICoreGraphicsContext.h +// OpenSwiftUI_SPI +// // Audited for RELEASE_2024 // Status: WIP -#include "CoreGraphicsContext.h" +#include "OpenSwiftUICoreGraphicsContext.h" #if OPENSWIFTUI_TARGET_OS_DARWIN #include -static _Thread_local __unsafe_unretained CoreGraphicsContext * _current = NULL; +static _Thread_local __unsafe_unretained OpenSwiftUICoreGraphicsContext * _current = NULL; IMP _pushContextIMP; IMP _popContextIMP; -@interface CoreGraphicsContext () { - CoreGraphicsContext *_next; +@interface OpenSwiftUICoreGraphicsContext () { + OpenSwiftUICoreGraphicsContext *_next; CGContextRef _ctx; } - (id)__createsImages; @end -@implementation CoreGraphicsContext +@implementation OpenSwiftUICoreGraphicsContext - (instancetype)initWithCGContext:(CGContextRef)ctx { static dispatch_once_t __once; @@ -45,7 +46,7 @@ - (void)push { _next = _current; _current = self; if (_pushContextIMP != NULL && _popContextIMP != NULL) { - typedef BOOL (*FUNC)(id, SEL, CoreGraphicsContext *); + typedef BOOL (*FUNC)(id, SEL, OpenSwiftUICoreGraphicsContext *); ((FUNC)(_pushContextIMP))(NULL, @selector(pushContext:), _current); } } @@ -53,7 +54,7 @@ - (void)push { - (void)pop { _current = _next; if (_pushContextIMP != NULL && _popContextIMP != NULL) { - typedef BOOL (*FUNC)(id, SEL, CoreGraphicsContext *); + typedef BOOL (*FUNC)(id, SEL, OpenSwiftUICoreGraphicsContext *); ((FUNC)(_popContextIMP))(NULL, @selector(popContext:), _current); } } @@ -66,7 +67,7 @@ - (CGContextRef)CGContext { return _ctx; } -+ (CoreGraphicsContext *)current { ++ (OpenSwiftUICoreGraphicsContext *)current { return _current; } diff --git a/Sources/COpenSwiftUICore/include/__CGPathParseString.h b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/__CGPathParseString.h similarity index 95% rename from Sources/COpenSwiftUICore/include/__CGPathParseString.h rename to Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/__CGPathParseString.h index 3a8e60f7..0aa5e572 100644 --- a/Sources/COpenSwiftUICore/include/__CGPathParseString.h +++ b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/__CGPathParseString.h @@ -1,6 +1,6 @@ // // __CGPathParseString.h -// COpenSwiftUI +// OpenSwiftUI_SPI #ifndef __CGPathParseString_h #define __CGPathParseString_h diff --git a/Sources/COpenSwiftUICore/Overlay/CoreGraphics/__CGPathParseString.m b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/__CGPathParseString.m similarity index 91% rename from Sources/COpenSwiftUICore/Overlay/CoreGraphics/__CGPathParseString.m rename to Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/__CGPathParseString.m index 308716ab..f3858f2a 100644 --- a/Sources/COpenSwiftUICore/Overlay/CoreGraphics/__CGPathParseString.m +++ b/Sources/OpenSwiftUI_SPI/Overlay/CoreGraphics/__CGPathParseString.m @@ -1,6 +1,6 @@ // // __CGPathParseString.m -// COpenSwiftUI +// OpenSwiftUI_SPI #import "__CGPathParseString.h" diff --git a/Sources/COpenSwiftUICore/README.md b/Sources/OpenSwiftUI_SPI/README.md similarity index 64% rename from Sources/COpenSwiftUICore/README.md rename to Sources/OpenSwiftUI_SPI/README.md index 44a57483..9ed23717 100644 --- a/Sources/COpenSwiftUICore/README.md +++ b/Sources/OpenSwiftUI_SPI/README.md @@ -1,3 +1,3 @@ -## COpenSwiftUICore +## OpenSwiftUI_SPI TODO: module name - OpenSwiftUI_SPI diff --git a/Sources/OpenSwiftUI_SPI/Shims/CoreFoundation_Private.c b/Sources/OpenSwiftUI_SPI/Shims/CoreFoundation_Private.c new file mode 100644 index 00000000..a6165b68 --- /dev/null +++ b/Sources/OpenSwiftUI_SPI/Shims/CoreFoundation_Private.c @@ -0,0 +1,22 @@ +// +// CoreFoundation_Private.c +// OpenSwiftUI_SPI + +#include "CoreFoundation_Private.h" +#include "dyld_Private.h" + +bool _OpenSwiftUICFMZEnabled(void); + +#if !OPENSWIFTUI_TARGET_OS_DARWIN +bool _CFMZEnabled(void) { + return _OpenSwiftUICFMZEnabled(); +} +#endif + +bool _OpenSwiftUICFMZEnabled(void) { + #if OPENSWIFTUI_TARGET_OS_OSX || OPENSWIFTUI_TARGET_OS_MACCATALYST + return dyld_get_active_platform() == DYLD_PLATFORM_MACCATALYST || dyld_get_active_platform() == DYLD_PLATFORM_IOS; + #else + return false; + #endif +} diff --git a/Sources/COpenSwiftUICore/include/CoreFoundation_Private.h b/Sources/OpenSwiftUI_SPI/Shims/CoreFoundation_Private.h similarity index 63% rename from Sources/COpenSwiftUICore/include/CoreFoundation_Private.h rename to Sources/OpenSwiftUI_SPI/Shims/CoreFoundation_Private.h index 91f2fb44..d832921b 100644 --- a/Sources/COpenSwiftUICore/include/CoreFoundation_Private.h +++ b/Sources/OpenSwiftUI_SPI/Shims/CoreFoundation_Private.h @@ -1,12 +1,15 @@ // // CoreFoundation_Private.h -// COpenSwiftUI +// OpenSwiftUI_SPI #ifndef CoreFoundation_Private_h #define CoreFoundation_Private_h #include "OpenSwiftUIBase.h" +/// Check if Marzipan is enabled. +/// +/// > Marzipan is the codename of "UIKit for macOS" / Mac Catalyst OPENSWIFTUI_EXPORT bool _CFMZEnabled(void); diff --git a/Sources/COpenSwiftUICore/include/OpenSwiftUI_SPI.h b/Sources/OpenSwiftUI_SPI/Shims/UIKitAppKit_Private.h similarity index 89% rename from Sources/COpenSwiftUICore/include/OpenSwiftUI_SPI.h rename to Sources/OpenSwiftUI_SPI/Shims/UIKitAppKit_Private.h index 28030a5d..af406ca0 100644 --- a/Sources/COpenSwiftUICore/include/OpenSwiftUI_SPI.h +++ b/Sources/OpenSwiftUI_SPI/Shims/UIKitAppKit_Private.h @@ -1,12 +1,12 @@ // -// OpenSwiftUI_SPI.h -// OpenSwiftUI +// UIKitAppKit_Private.h +// OpenSwiftUI_SPI // // Audited for RELEASE_2021 // Status: WIP -#ifndef OpenSwiftUI_SPI_h -#define OpenSwiftUI_SPI_h +#ifndef UIKitAppKit_Private_h +#define UIKitAppKit_Private_h #include "OpenSwiftUIBase.h" @@ -59,4 +59,4 @@ OPENSWIFTUI_ASSUME_NONNULL_END #endif /* UIKit.h / AppKit.h */ -#endif /* OpenSwiftUI_SPI_h */ +#endif /* UIKitAppKit_Private_h */ diff --git a/Sources/COpenSwiftUICore/Shims/dyld_Private.c b/Sources/OpenSwiftUI_SPI/Shims/dyld_Private.c similarity index 92% rename from Sources/COpenSwiftUICore/Shims/dyld_Private.c rename to Sources/OpenSwiftUI_SPI/Shims/dyld_Private.c index 7b7f5c59..1fcd890e 100644 --- a/Sources/COpenSwiftUICore/Shims/dyld_Private.c +++ b/Sources/OpenSwiftUI_SPI/Shims/dyld_Private.c @@ -1,6 +1,6 @@ // // dyld_Private.c -// COpenSwiftUI +// OpenSwiftUI_SPI #include "dyld_Private.h" diff --git a/Sources/OpenSwiftUI_SPI/Shims/dyld_Private.h b/Sources/OpenSwiftUI_SPI/Shims/dyld_Private.h new file mode 100644 index 00000000..431da8f6 --- /dev/null +++ b/Sources/OpenSwiftUI_SPI/Shims/dyld_Private.h @@ -0,0 +1,87 @@ +// +// dyld_Private.h +// OpenSwiftUI_SPI +// +// Audited for RELEASE_2024 +// Status: Complete + +#ifndef dyld_Private_h +#define dyld_Private_h + +#include "OpenSwiftUIBase.h" + +typedef uint32_t dyld_platform_t; + +typedef OPENSWIFTUI_ENUM(dyld_platform_t, DYLD_PLATFORM) { + DYLD_PLATFORM_UNKNOWN = 0, + DYLD_PLATFORM_MACOS = 1, + DYLD_PLATFORM_IOS = 2, + DYLD_PLATFORM_TVOS = 3, + DYLD_PLATFORM_WATCHOS = 4, + DYLD_PLATFORM_BRIDGEOS = 5, + DYLD_PLATFORM_MACCATALYST = 6, + DYLD_PLATFORM_IOSSIMULATOR = 7, + DYLD_PLATFORM_TVOSSIMULATOR = 8, + DYLD_PLATFORM_WATCHOSSIMULATOR = 9, + DYLD_PLATFORM_DRIVERKIT = 10, + DYLD_PLATFORM_XROS = 11, + DYLD_PLATFORM_XROS_SIMULATOR = 12 +}; + +typedef OPENSWIFTUI_ENUM(uint32_t, DYLD_MACOSX_VERSION) { + DYLD_MACOSX_VERSION_10_4 = 0x000A0400, + DYLD_MACOSX_VERSION_10_5 = 0x000A0500, + DYLD_MACOSX_VERSION_10_6 = 0x000A0600, + DYLD_MACOSX_VERSION_10_7 = 0x000A0700, + DYLD_MACOSX_VERSION_10_8 = 0x000A0800, + DYLD_MACOSX_VERSION_10_9 = 0x000A0900, + DYLD_MACOSX_VERSION_10_10 = 0x000A0A00, + DYLD_MACOSX_VERSION_10_11 = 0x000A0B00, + DYLD_MACOSX_VERSION_10_12 = 0x000A0C00, + DYLD_MACOSX_VERSION_10_13 = 0x000A0D00, + DYLD_MACOSX_VERSION_10_14 = 0x000A0E00, + DYLD_MACOSX_VERSION_10_15 = 0x000A0F00, + DYLD_MACOSX_VERSION_15_0 = 0x000F0000, + /// For Test Only + DYLD_MACOSX_VERSION_16_0 = 0x00100000, +}; + +typedef OPENSWIFTUI_ENUM(uint32_t, DYLD_IOS_VERSION) { + DYLD_IOS_VERSION_2_0 = 0x00020000, + DYLD_IOS_VERSION_2_1 = 0x00020100, + DYLD_IOS_VERSION_2_2 = 0x00020200, + DYLD_IOS_VERSION_3_0 = 0x00030000, + DYLD_IOS_VERSION_3_1 = 0x00030100, + DYLD_IOS_VERSION_3_2 = 0x00030200, + DYLD_IOS_VERSION_4_0 = 0x00040000, + DYLD_IOS_VERSION_4_1 = 0x00040100, + DYLD_IOS_VERSION_4_2 = 0x00040200, + DYLD_IOS_VERSION_4_3 = 0x00040300, + DYLD_IOS_VERSION_5_0 = 0x00050000, + DYLD_IOS_VERSION_5_1 = 0x00050100, + DYLD_IOS_VERSION_6_0 = 0x00060000, + DYLD_IOS_VERSION_6_1 = 0x00060100, + DYLD_IOS_VERSION_7_0 = 0x00070000, + DYLD_IOS_VERSION_7_1 = 0x00070100, + DYLD_IOS_VERSION_8_0 = 0x00080000, + DYLD_IOS_VERSION_8_1 = 0x00080100, + DYLD_IOS_VERSION_8_2 = 0x00080200, + DYLD_IOS_VERSION_9_0 = 0x00090000, + DYLD_IOS_VERSION_18_0 = 0x00120000, + /// For Test Only + DYLD_IOS_VERSION_19_0 = 0x00130000, +}; + +typedef struct { + dyld_platform_t platform; + uint32_t version; +} dyld_build_version_t; + +// Always return true on non-Darwin platform +OPENSWIFTUI_EXPORT +bool dyld_program_sdk_at_least(dyld_build_version_t version); + +OPENSWIFTUI_EXPORT +dyld_platform_t dyld_get_active_platform(void); + +#endif /* dyld_Private_h */ diff --git a/Sources/COpenSwiftUICore/include/kdebug_Private.h b/Sources/OpenSwiftUI_SPI/Shims/kdebug_Private.h similarity index 99% rename from Sources/COpenSwiftUICore/include/kdebug_Private.h rename to Sources/OpenSwiftUI_SPI/Shims/kdebug_Private.h index 032502ca..a959d245 100644 --- a/Sources/COpenSwiftUICore/include/kdebug_Private.h +++ b/Sources/OpenSwiftUI_SPI/Shims/kdebug_Private.h @@ -1,6 +1,6 @@ // // kdebug_Private.h -// COpenSwiftUICore +// OpenSwiftUI_SPI // // Audited for RELEASE_2024 // Status: Complete diff --git a/Sources/COpenSwiftUICore/Other/LockedPointer.c b/Sources/OpenSwiftUI_SPI/Util/LockedPointer.c similarity index 100% rename from Sources/COpenSwiftUICore/Other/LockedPointer.c rename to Sources/OpenSwiftUI_SPI/Util/LockedPointer.c diff --git a/Sources/COpenSwiftUICore/include/LockedPointer.h b/Sources/OpenSwiftUI_SPI/Util/LockedPointer.h similarity index 100% rename from Sources/COpenSwiftUICore/include/LockedPointer.h rename to Sources/OpenSwiftUI_SPI/Util/LockedPointer.h diff --git a/Sources/COpenSwiftUICore/Other/MovableLock.c b/Sources/OpenSwiftUI_SPI/Util/MovableLock.c similarity index 100% rename from Sources/COpenSwiftUICore/Other/MovableLock.c rename to Sources/OpenSwiftUI_SPI/Util/MovableLock.c diff --git a/Sources/COpenSwiftUICore/include/MovableLock.h b/Sources/OpenSwiftUI_SPI/Util/MovableLock.h similarity index 100% rename from Sources/COpenSwiftUICore/include/MovableLock.h rename to Sources/OpenSwiftUI_SPI/Util/MovableLock.h diff --git a/Sources/COpenSwiftUICore/Other/ProtocolDescriptor.c b/Sources/OpenSwiftUI_SPI/Util/ProtocolDescriptor.c similarity index 96% rename from Sources/COpenSwiftUICore/Other/ProtocolDescriptor.c rename to Sources/OpenSwiftUI_SPI/Util/ProtocolDescriptor.c index e52d0964..50ad9d9a 100644 --- a/Sources/COpenSwiftUICore/Other/ProtocolDescriptor.c +++ b/Sources/OpenSwiftUI_SPI/Util/ProtocolDescriptor.c @@ -1,6 +1,6 @@ // // ProtocolDescriptor.c -// COpenSwiftUICore +// OpenSwiftUI_SPI #include "ProtocolDescriptor.h" diff --git a/Sources/COpenSwiftUICore/include/ProtocolDescriptor.h b/Sources/OpenSwiftUI_SPI/Util/ProtocolDescriptor.h similarity index 100% rename from Sources/COpenSwiftUICore/include/ProtocolDescriptor.h rename to Sources/OpenSwiftUI_SPI/Util/ProtocolDescriptor.h diff --git a/Sources/COpenSwiftUICore/Other/TLS.c b/Sources/OpenSwiftUI_SPI/Util/TLS.c similarity index 97% rename from Sources/COpenSwiftUICore/Other/TLS.c rename to Sources/OpenSwiftUI_SPI/Util/TLS.c index 72d9ad5c..781cd59b 100644 --- a/Sources/COpenSwiftUICore/Other/TLS.c +++ b/Sources/OpenSwiftUI_SPI/Util/TLS.c @@ -1,6 +1,6 @@ // // TLS.c -// COpenSwiftUICore +// OpenSwiftUI_SPI // // Audited for RELEASE_2024 // Status: Complete diff --git a/Sources/COpenSwiftUICore/include/TLS.h b/Sources/OpenSwiftUI_SPI/Util/TLS.h similarity index 94% rename from Sources/COpenSwiftUICore/include/TLS.h rename to Sources/OpenSwiftUI_SPI/Util/TLS.h index 2df6ad72..f9100046 100644 --- a/Sources/COpenSwiftUICore/include/TLS.h +++ b/Sources/OpenSwiftUI_SPI/Util/TLS.h @@ -1,6 +1,6 @@ // // TLS.h -// COpenSwiftUICore +// OpenSwiftUI_SPI // // Audited for RELEASE_2024 // Status: Complete diff --git a/Sources/COpenSwiftUICore/include/ViewSystem.h b/Sources/OpenSwiftUI_SPI/Util/ViewSystem.h similarity index 92% rename from Sources/COpenSwiftUICore/include/ViewSystem.h rename to Sources/OpenSwiftUI_SPI/Util/ViewSystem.h index 561c1fd3..95405c8a 100644 --- a/Sources/COpenSwiftUICore/include/ViewSystem.h +++ b/Sources/OpenSwiftUI_SPI/Util/ViewSystem.h @@ -1,6 +1,7 @@ // // ViewSystem.h -// COpenSwiftUICore +// OpenSwiftUI_SPI +// // Audited for RELEASE_2024 // Status: Complete diff --git a/Tests/OpenSwiftUICoreTests/Data/Other/2021/LockedPointerTests.swift b/Tests/OpenSwiftUICoreTests/Data/Other/2021/LockedPointerTests.swift index 00e27d8e..0f8d9968 100644 --- a/Tests/OpenSwiftUICoreTests/Data/Other/2021/LockedPointerTests.swift +++ b/Tests/OpenSwiftUICoreTests/Data/Other/2021/LockedPointerTests.swift @@ -8,7 +8,7 @@ #if OPENSWIFTUI_RELEASE_2021 @testable import OpenSwiftUICore -import COpenSwiftUICore +import OpenSwiftUI_SPI import Testing struct LockedPointerTests { diff --git a/Tests/OpenSwiftUI_SPITests/Overlay/CoreGraphics/OpenSwiftUICoreColorTests.swift b/Tests/OpenSwiftUI_SPITests/Overlay/CoreGraphics/OpenSwiftUICoreColorTests.swift new file mode 100644 index 00000000..f4687635 --- /dev/null +++ b/Tests/OpenSwiftUI_SPITests/Overlay/CoreGraphics/OpenSwiftUICoreColorTests.swift @@ -0,0 +1,109 @@ +// +// CoreFoundationPrivateTests.swift +// OpenSwiftUI_SPITests + +import Numerics +import OpenSwiftUI_SPI +import OpenSwiftUICore +import Testing + +#if canImport(Darwin) + +#if os(macOS) +import AppKit +#elseif os(iOS) +import UIKit +#endif + +@MainActor +struct OpenSwiftUICoreColorTests { + @Test + func platformColorGetComponents() { + #if os(macOS) + let blackColor = NSColor(colorSpace: .extendedSRGB, components: [0, 0, 0, 1], count: 4) + let grayColor = NSColor(colorSpace: .extendedSRGB, components: [0.5, 0.5, 0.5, 1], count: 4) + let whiteColor = NSColor(colorSpace: .extendedSRGB, components: [1, 1, 1, 1], count: 4) + #elseif os(iOS) + let blackColor = UIColor(white: 0, alpha: 1) + let grayColor = UIColor(white: 0.5, alpha: 1) + let whiteColor = UIColor(white: 1, alpha: 1) + #endif + + var r: CGFloat = 0 + var g: CGFloat = 0 + var b: CGFloat = 0 + var a: CGFloat = 0 + #expect(OpenSwiftUICoreColorPlatformColorGetComponents(isAppKitBased(), blackColor, &r, &g, &b, &a) == true) + #expect(r.isApproximatelyEqual(to: 0)) + #expect(g.isApproximatelyEqual(to: 0)) + #expect(b.isApproximatelyEqual(to: 0)) + #expect(a.isApproximatelyEqual(to: 1)) + #expect(OpenSwiftUICoreColorPlatformColorGetComponents(isAppKitBased(), grayColor, &r, &g, &b, &a) == true) + #expect(r.isApproximatelyEqual(to: 0.5)) + #expect(g.isApproximatelyEqual(to: 0.5)) + #expect(b.isApproximatelyEqual(to: 0.5)) + #expect(a.isApproximatelyEqual(to: 1)) + #expect(OpenSwiftUICoreColorPlatformColorGetComponents(isAppKitBased(), whiteColor, &r, &g, &b, &a) == true) + #expect(r.isApproximatelyEqual(to: 1)) + #expect(g.isApproximatelyEqual(to: 1)) + #expect(b.isApproximatelyEqual(to: 1)) + #expect(a.isApproximatelyEqual(to: 1)) + } + + @Test + func platformColorForRGBA() throws { + let blackColorObject = try #require(OpenSwiftUICorePlatformColorForRGBA(isAppKitBased(), 0, 0, 0, 1)) + let greyColorObject = try #require(OpenSwiftUICorePlatformColorForRGBA(isAppKitBased(), 0.5, 0.5, 0.5, 1)) + let whiteColorObject = try #require(OpenSwiftUICorePlatformColorForRGBA(isAppKitBased(), 1, 1, 1, 1)) + #if os(macOS) + let blackColor = try #require((blackColorObject as? NSColor)?.usingColorSpace(.deviceRGB)) + let greyColor = try #require(greyColorObject as? NSColor) + let whiteColor = try #require(whiteColorObject as? NSColor) + var r: CGFloat = 0 + var g: CGFloat = 0 + var b: CGFloat = 0 + var a: CGFloat = 0 + blackColor.getRed(&r, green: &g, blue: &b, alpha: &a) + #expect(r.isApproximatelyEqual(to: 0)) + #expect(g.isApproximatelyEqual(to: 0)) + #expect(b.isApproximatelyEqual(to: 0)) + #expect(a.isApproximatelyEqual(to: 1)) + greyColor.getRed(&r, green: &g, blue: &b, alpha: &a) + #expect(r.isApproximatelyEqual(to: 0.5)) + #expect(g.isApproximatelyEqual(to: 0.5)) + #expect(b.isApproximatelyEqual(to: 0.5)) + #expect(a.isApproximatelyEqual(to: 1)) + whiteColor.getRed(&r, green: &g, blue: &b, alpha: &a) + #expect(r.isApproximatelyEqual(to: 1)) + #expect(g.isApproximatelyEqual(to: 1)) + #expect(b.isApproximatelyEqual(to: 1)) + #expect(a.isApproximatelyEqual(to: 1)) + #elseif os(iOS) + let blackColor = try #require(blackColorObject as? UIColor) + let greyColor = try #require(greyColorObject as? UIColor) + let whiteColor = try #require(whiteColorObject as? UIColor) + var white: CGFloat = 0 + var alpha: CGFloat = 0 + blackColor.getWhite(&white, alpha: &alpha) + #expect(white.isApproximatelyEqual(to: 0)) + #expect(alpha.isApproximatelyEqual(to: 1)) + greyColor.getWhite(&white, alpha: &alpha) + #expect(white.isApproximatelyEqual(to: 0.5)) + #expect(alpha.isApproximatelyEqual(to: 1)) + whiteColor.getWhite(&white, alpha: &alpha) + #expect(white.isApproximatelyEqual(to: 1.0000001192092896)) + #expect(alpha.isApproximatelyEqual(to: 1)) + #endif + } + + @Test + func getKitColorClass() { + let colorClass: AnyClass? = OpenSwiftUICoreColorGetKitColorClass(isAppKitBased()) + #if os(macOS) + #expect(colorClass == NSColor.self) + #elseif os(iOS) + #expect(colorClass == UIColor.self) + #endif + } +} +#endif diff --git a/Tests/OpenSwiftUI_SPITests/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.swift b/Tests/OpenSwiftUI_SPITests/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.swift new file mode 100644 index 00000000..3de9d48f --- /dev/null +++ b/Tests/OpenSwiftUI_SPITests/Overlay/CoreGraphics/OpenSwiftUICoreGraphicsContext.swift @@ -0,0 +1,14 @@ +// +// OpenSwiftUICoreGraphicsContext.swift +// OpenSwiftUI_SPITests + +import OpenSwiftUI_SPI +import Testing + +#if canImport(Darwin) + +struct OpenSwiftUICoreGraphicsContext { + +} + +#endif diff --git a/Tests/OpenSwiftUI_SPITests/README.md b/Tests/OpenSwiftUI_SPITests/README.md new file mode 100644 index 00000000..d9fa887c --- /dev/null +++ b/Tests/OpenSwiftUI_SPITests/README.md @@ -0,0 +1,7 @@ +## OpenSwiftUI_SPITests + +Test API of OpenSwiftUI_SPI + +```swift +import OpenSwiftUI_SPI +``` diff --git a/Tests/OpenSwiftUI_SPITests/Scaffolding.swift b/Tests/OpenSwiftUI_SPITests/Scaffolding.swift new file mode 100644 index 00000000..43ada21a --- /dev/null +++ b/Tests/OpenSwiftUI_SPITests/Scaffolding.swift @@ -0,0 +1,18 @@ +// +// Scaffolding.swift +// +// +// Created by Kyle on 2023/11/8. +// + +import Testing +import XCTest + +#if compiler(<6.0) +// FIXME: Leave Scaffolding since we still use 5.10 toolchain on non-Darwin platform +final class AllTests: XCTestCase { + func testAll() async { + await XCTestScaffold.runAllTests(hostedBy: self) + } +} +#endif diff --git a/Tests/OpenSwiftUI_SPITests/Shims/CoreFoundationPrivateTests.swift b/Tests/OpenSwiftUI_SPITests/Shims/CoreFoundationPrivateTests.swift new file mode 100644 index 00000000..4588394d --- /dev/null +++ b/Tests/OpenSwiftUI_SPITests/Shims/CoreFoundationPrivateTests.swift @@ -0,0 +1,28 @@ +// +// CoreFoundationPrivateTests.swift +// OpenSwiftUI_SPITests + +import OpenSwiftUI_SPI +import Testing + +struct CoreFoundationPrivateTests { + @Test + func CFMZEnabled() { + let result = _CFMZEnabled() +#if canImport(Darwin) + #if targetEnvironment(macCatalyst) + #expect(result == true) + #elseif targetEnvironment(simulator) + #expect(result == false) + #else + #if os(iOS) + #expect(result == true) + #else + #expect(result == false) + #endif + #endif +#else + #expect(result == false) +#endif + } +} diff --git a/Tests/OpenSwiftUI_SPITests/Shims/DyldPrivateTests.swift b/Tests/OpenSwiftUI_SPITests/Shims/DyldPrivateTests.swift new file mode 100644 index 00000000..721f6d5e --- /dev/null +++ b/Tests/OpenSwiftUI_SPITests/Shims/DyldPrivateTests.swift @@ -0,0 +1,120 @@ +// +// DyldPrivateTests.swift +// OpenSwiftUI_SPITests + +import OpenSwiftUI_SPI +import Testing + +struct DyldPrivateTests { + @Test + func sdkAtLeastVersion() { +#if canImport(Darwin) + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: .max + )) == false) + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: .min + )) == true) + + #if os(iOS) + if #unavailable(iOS 19) { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_IOS_VERSION._19_0.rawValue + )) == false) + if #unavailable(iOS 18) { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_IOS_VERSION._18_0.rawValue + )) == false) + } else { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_IOS_VERSION._18_0.rawValue + )) == true) + } + } else { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_IOS_VERSION._19_0.rawValue + )) == true) + } + #elseif os(macOS) + if #unavailable(macOS 16) { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_MACOSX_VERSION._16_0.rawValue + )) == false) + if #unavailable(macOS 15) { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_MACOSX_VERSION._15_0.rawValue + )) == false) + } else { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_MACOSX_VERSION._15_0.rawValue + )) == true) + } + } else { + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: DYLD_MACOSX_VERSION._16_0.rawValue + )) == true) + } + #else + fatalError("Unsupported Darwin platform") + #endif + +#else + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: .max + )) == true) + #expect(dyld_program_sdk_at_least(.init( + platform: dyld_get_active_platform(), + version: .min + )) == true) +#endif + } + + @Test + func activePlatform() throws { + let platform = try #require(DYLD_PLATFORM(rawValue: dyld_get_active_platform())) +#if canImport(Darwin) + #if targetEnvironment(macCatalyst) + #expect(platform == .MACCATALYST) + #elseif targetEnvironment(simulator) + #if os(iOS) + #expect(platform == .IOSSIMULATOR) + #elseif os(tvOS) + #expect(platform == .TVOSSIMULATOR) + #elseif os(watchOS) + #expect(platform == .WATCHOSSIMULATOR) + #elseif os(visionOS) + #expect(platform == .XROS_SIMULATOR) + #else + fatalError("Unsupported Darwin simulator platform") + #endif + #else + #if os(iOS) + #expect(platform == .IOS) + #elseif os(macOS) + #expect(platform == .MACOS) + #elseif os(tvOS) + #expect(platform == .TVOS) + #elseif os(watchOS) + #expect(platform == .WATCHOS) + #elseif os(visionOS) + #expect(platform == .XROS) + #else + fatalError("Unsupported Darwin platform") + #endif + #endif +#else + #expect(platform == .UNKNOWN) +#endif + } +} diff --git a/Tests/OpenSwiftUI_SPITests/Shims/KDebugPrivateTests.swift b/Tests/OpenSwiftUI_SPITests/Shims/KDebugPrivateTests.swift new file mode 100644 index 00000000..85d6dcdf --- /dev/null +++ b/Tests/OpenSwiftUI_SPITests/Shims/KDebugPrivateTests.swift @@ -0,0 +1,15 @@ +// +// KDebugPrivateTests.swift +// OpenSwiftUI_SPITests + +import OpenSwiftUI_SPI +import Testing + +#if canImport(Darwin) +struct KDebugPrivateTests { + @Test + func enable() { + #expect(kdebug_is_enabled(0) == false) + } +} +#endif diff --git a/Tests/OpenSwiftUICoreTests/COpenSwiftUICore/MovableLockTests.swift b/Tests/OpenSwiftUI_SPITests/Util/MovableLockTests.swift similarity index 89% rename from Tests/OpenSwiftUICoreTests/COpenSwiftUICore/MovableLockTests.swift rename to Tests/OpenSwiftUI_SPITests/Util/MovableLockTests.swift index 0f348d6a..bb8c7825 100644 --- a/Tests/OpenSwiftUICoreTests/COpenSwiftUICore/MovableLockTests.swift +++ b/Tests/OpenSwiftUI_SPITests/Util/MovableLockTests.swift @@ -1,11 +1,8 @@ // // MovableLockTests.swift -// -// -// Created by Kyle on 2024/3/16. -// +// OpenSwiftUI_SPITests -import COpenSwiftUICore +import OpenSwiftUI_SPI import Testing #if canImport(Darwin)