Skip to content

Commit 204d9ae

Browse files
committed
Update DYLD and CoreFoundation private API
1 parent 2888a61 commit 204d9ae

File tree

9 files changed

+114
-98
lines changed

9 files changed

+114
-98
lines changed

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ if warningsAsErrorsCondition {
8686
sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"]))
8787
}
8888

89+
// NOTE: Mac Catalyst should use macOS-varient build of OpenSwiftUICore.framework and Mac Catalyst/UIKitForMac varient of OpenSwiftUI.framework
90+
// Add `|| Mac Catalyst` check everywhere in `OpenSwiftUICore` and `COpenSwiftUICore`.
8991
let openSwiftUICoreTarget = Target.target(
9092
name: "OpenSwiftUICore",
9193
dependencies: [

Sources/COpenSwiftUICore/OpenSwiftUITargetConditionals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@
145145
#define OPENSWIFTUI_TARGET_OS_IOS TARGET_OS_IOS
146146
#define OPENSWIFTUI_TARGET_OS_WATCH TARGET_OS_WATCH
147147
#define OPENSWIFTUI_TARGET_OS_TV TARGET_OS_TV
148+
#define OPENSWIFTUI_TARGET_OS_MACCATALYST TARGET_OS_MACCATALYST
148149
#else
149150
// iOS, watchOS, and tvOS are not supported
150151
#define OPENSWIFTUI_TARGET_OS_IPHONE 0
151152
#define OPENSWIFTUI_TARGET_OS_IOS 0
152153
#define OPENSWIFTUI_TARGET_OS_WATCH 0
153154
#define OPENSWIFTUI_TARGET_OS_TV 0
155+
#define OPENSWIFTUI_TARGET_OS_MACCATALYST 0
154156
#endif
155157

156158
/* OpenSwiftUI Addition End */

Sources/COpenSwiftUICore/Overlay/CoreGraphics/OpenSwiftUICoreColor.m

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
Class OpenSwiftUICoreColorClass(BOOL isAppKitBased);
1414

15-
#if OPENSWIFTUI_TARGET_OS_OSX
15+
#if OPENSWIFTUI_TARGET_OS_OSX || OPENSWIFTUI_TARGET_OS_MACCATALYST
1616
id NSColorSpaceForCGColorSpace(CGColorSpaceRef cgColorSpace);
1717
Class NSColorSpaceClass(void);
1818
#endif
@@ -25,7 +25,7 @@ BOOL OpenSwiftUICoreColorPlatformColorGetComponents(BOOL system, id color, CGFlo
2525
if (!colorClass) {
2626
return NO;
2727
}
28-
#if OPENSWIFTUI_TARGET_OS_OSX
28+
#if OPENSWIFTUI_TARGET_OS_OSX || OPENSWIFTUI_TARGET_OS_MACCATALYST
2929
if (system) {
3030
id colorSpace = NSColorSpaceForCGColorSpace(CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB));
3131
NSColor *nameSpaceColor = [color colorUsingColorSpace:colorSpace];
@@ -46,7 +46,7 @@ BOOL OpenSwiftUICoreColorPlatformColorGetComponents(BOOL system, id color, CGFlo
4646
if (!colorClass) {
4747
return nil;
4848
}
49-
#if OPENSWIFTUI_TARGET_OS_OSX
49+
#if OPENSWIFTUI_TARGET_OS_OSX || OPENSWIFTUI_TARGET_OS_MACCATALYST
5050
if (system) {
5151
id colorSpace = NSColorSpaceForCGColorSpace(CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB));
5252
return [colorClass colorWithColorSpace:colorSpace components:(CGFloat[]){red, green, blue, alpha} count:4];
@@ -60,19 +60,26 @@ Class OpenSwiftUICoreColorGetKitColorClass(BOOL system) {
6060
}
6161

6262
Class OpenSwiftUICoreColorClass(BOOL system) {
63-
static BOOL isValid = false;
63+
static BOOL isValid = true;
6464
static Class colorClass;
6565
static dispatch_once_t once;
6666
dispatch_once(&once, ^{
67-
if (system) {
68-
Class class = NSClassFromString(@"NSColor");
67+
#if OPENSWIFTUI_TARGET_OS_OSX || OPENSWIFTUI_TARGET_OS_MACCATALYST
68+
if (!system) {
69+
Class class = NSClassFromString(@"UIColor");
6970
colorClass = class;
7071
isValid = class != nil;
71-
} else {
72-
Class class = NSClassFromString(@"UIColor");
72+
}
73+
if (system) {
74+
Class class = NSClassFromString(@"NSColor");
7375
colorClass = class;
7476
isValid = class != nil;
7577
}
78+
#else
79+
Class class = NSClassFromString(@"UIColor");
80+
colorClass = class;
81+
isValid = class != nil;
82+
#endif
7683
});
7784
if (isValid) {
7885
return colorClass;
@@ -81,7 +88,7 @@ Class OpenSwiftUICoreColorClass(BOOL system) {
8188
}
8289
}
8390

84-
#if OPENSWIFTUI_TARGET_OS_OSX
91+
#if OPENSWIFTUI_TARGET_OS_OSX || OPENSWIFTUI_TARGET_OS_MACCATALYST
8592
id NSColorSpaceForCGColorSpace(CGColorSpaceRef cgColorSpace) {
8693
Class colorSpaceClass = NSColorSpaceClass();
8794
if (colorSpaceClass) {

Sources/COpenSwiftUICore/Shims/CoreFoundation_Private.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
#include "dyld_Private.h"
77

88
#if !OPENSWIFTUI_TARGET_OS_DARWIN
9-
10-
#define PLATFORM_IOS 2
11-
#define PLATFORM_MACCATALYST 6
12-
139
bool _CFMZEnabled(void) {
14-
return dyld_get_active_platform() == PLATFORM_MACCATALYST || dyld_get_active_platform() == PLATFORM_IOS;
10+
return _OpenSwiftUICFMZEnabled;
1511
}
1612
#endif
13+
14+
bool _OpenSwiftUICFMZEnabled(void) {
15+
#if OPENSWIFTUI_TARGET_OS_OSX || OPENSWIFTUI_TARGET_OS_MACCATALYST
16+
return dyld_get_active_platform() == DYLD_PLATFORM_MACCATALYST || dyld_get_active_platform() == DYLD_PLATFORM_IOS;
17+
#else
18+
return false;
19+
#endif
20+
}

Sources/COpenSwiftUICore/Shims/CoreFoundation_Private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#include "OpenSwiftUIBase.h"
99

10+
/// Check if Marzipan is enabled.
11+
///
12+
/// > Marzipan is the codename of "UIKit for macOS" / Mac Catalyst
1013
OPENSWIFTUI_EXPORT
1114
bool _CFMZEnabled(void);
1215

Sources/COpenSwiftUICore/Shims/dyld_Private.h

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,64 @@
1212

1313
typedef uint32_t dyld_platform_t;
1414

15-
typedef OPENSWIFTUI_ENUM(dyld_platform_t, DyldPlatform) {
16-
unknown = 0,
17-
macOS = 1,
18-
iOS = 2,
19-
tvOS = 3,
20-
watchOS = 4,
21-
bridgeOS = 5,
22-
macCatalyst = 6,
23-
iOSSimulator = 7,
24-
tvOSSimulator = 8,
25-
watchOSSimulator = 9,
26-
driverKit = 10,
27-
xROS = 11,
28-
xROSSimulator = 12,
15+
typedef OPENSWIFTUI_ENUM(dyld_platform_t, DYLD_PLATFORM) {
16+
DYLD_PLATFORM_UNKNOWN = 0,
17+
DYLD_PLATFORM_MACOS = 1,
18+
DYLD_PLATFORM_IOS = 2,
19+
DYLD_PLATFORM_TVOS = 3,
20+
DYLD_PLATFORM_WATCHOS = 4,
21+
DYLD_PLATFORM_BRIDGEOS = 5,
22+
DYLD_PLATFORM_MACCATALYST = 6,
23+
DYLD_PLATFORM_IOSSIMULATOR = 7,
24+
DYLD_PLATFORM_TVOSSIMULATOR = 8,
25+
DYLD_PLATFORM_WATCHOSSIMULATOR = 9,
26+
DYLD_PLATFORM_DRIVERKIT = 10,
27+
DYLD_PLATFORM_XROS = 11,
28+
DYLD_PLATFORM_XROS_SIMULATOR = 12
2929
};
3030

31-
typedef OPENSWIFTUI_ENUM(uint32_t, DyldMacOSXVersion) {
32-
V10_4 = 0x000A0400,
33-
V10_5 = 0x000A0500,
34-
V10_6 = 0x000A0600,
35-
V10_7 = 0x000A0700,
36-
V10_8 = 0x000A0800,
37-
V10_9 = 0x000A0900,
38-
V10_10 = 0x000A0A00,
39-
V10_11 = 0x000A0B00,
40-
V10_12 = 0x000A0C00,
41-
V10_13 = 0x000A0D00,
42-
V10_14 = 0x000A0E00,
43-
V10_15 = 0x000A0F00,
44-
V15_0 = 0x000F0000,
31+
typedef OPENSWIFTUI_ENUM(uint32_t, DYLD_MACOSX_VERSION) {
32+
DYLD_MACOSX_VERSION_10_4 = 0x000A0400,
33+
DYLD_MACOSX_VERSION_10_5 = 0x000A0500,
34+
DYLD_MACOSX_VERSION_10_6 = 0x000A0600,
35+
DYLD_MACOSX_VERSION_10_7 = 0x000A0700,
36+
DYLD_MACOSX_VERSION_10_8 = 0x000A0800,
37+
DYLD_MACOSX_VERSION_10_9 = 0x000A0900,
38+
DYLD_MACOSX_VERSION_10_10 = 0x000A0A00,
39+
DYLD_MACOSX_VERSION_10_11 = 0x000A0B00,
40+
DYLD_MACOSX_VERSION_10_12 = 0x000A0C00,
41+
DYLD_MACOSX_VERSION_10_13 = 0x000A0D00,
42+
DYLD_MACOSX_VERSION_10_14 = 0x000A0E00,
43+
DYLD_MACOSX_VERSION_10_15 = 0x000A0F00,
44+
DYLD_MACOSX_VERSION_15_0 = 0x000F0000,
4545
/// For Test Only
46-
V16_0 = 0x00100000,
46+
DYLD_MACOSX_VERSION_16_0 = 0x00100000,
4747
};
4848

49-
typedef OPENSWIFTUI_ENUM(uint32_t, DyldIOSVersion) {
50-
V2_0 = 0x00020000,
51-
V2_1 = 0x00020100,
52-
V2_2 = 0x00020200,
53-
V3_0 = 0x00030000,
54-
V3_1 = 0x00030100,
55-
V3_2 = 0x00030200,
56-
V4_0 = 0x00040000,
57-
V4_1 = 0x00040100,
58-
V4_2 = 0x00040200,
59-
V4_3 = 0x00040300,
60-
V5_0 = 0x00050000,
61-
V5_1 = 0x00050100,
62-
V6_0 = 0x00060000,
63-
V6_1 = 0x00060100,
64-
V7_0 = 0x00070000,
65-
V7_1 = 0x00070100,
66-
V8_0 = 0x00080000,
67-
V8_1 = 0x00080100,
68-
V8_2 = 0x00080200,
69-
V9_0 = 0x00090000,
70-
V18_0 = 0x00120000,
49+
typedef OPENSWIFTUI_ENUM(uint32_t, DYLD_IOS_VERSION) {
50+
DYLD_IOS_VERSION_2_0 = 0x00020000,
51+
DYLD_IOS_VERSION_2_1 = 0x00020100,
52+
DYLD_IOS_VERSION_2_2 = 0x00020200,
53+
DYLD_IOS_VERSION_3_0 = 0x00030000,
54+
DYLD_IOS_VERSION_3_1 = 0x00030100,
55+
DYLD_IOS_VERSION_3_2 = 0x00030200,
56+
DYLD_IOS_VERSION_4_0 = 0x00040000,
57+
DYLD_IOS_VERSION_4_1 = 0x00040100,
58+
DYLD_IOS_VERSION_4_2 = 0x00040200,
59+
DYLD_IOS_VERSION_4_3 = 0x00040300,
60+
DYLD_IOS_VERSION_5_0 = 0x00050000,
61+
DYLD_IOS_VERSION_5_1 = 0x00050100,
62+
DYLD_IOS_VERSION_6_0 = 0x00060000,
63+
DYLD_IOS_VERSION_6_1 = 0x00060100,
64+
DYLD_IOS_VERSION_7_0 = 0x00070000,
65+
DYLD_IOS_VERSION_7_1 = 0x00070100,
66+
DYLD_IOS_VERSION_8_0 = 0x00080000,
67+
DYLD_IOS_VERSION_8_1 = 0x00080100,
68+
DYLD_IOS_VERSION_8_2 = 0x00080200,
69+
DYLD_IOS_VERSION_9_0 = 0x00090000,
70+
DYLD_IOS_VERSION_18_0 = 0x00120000,
7171
/// For Test Only
72-
V19_0 = 0x00130000,
72+
DYLD_IOS_VERSION_19_0 = 0x00130000,
7373
};
7474

7575
typedef struct {

Sources/OpenSwiftUICore/Graphic/Color/CoreColor+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// CoreColor+Extension.swift
3-
// OpenSwiftUI
3+
// OpenSwiftUICore
44
//
55
// Audited for RELEASE_2024
66
// Status: Complete

Sources/OpenSwiftUICore/Util/Utils.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ func asOptional<Value>(_ value: Value) -> Value? {
1515
return optionalValue
1616
}
1717

18+
#if canImport(Darwin)
19+
20+
// NOTE: use runtime check instead of #if targetEnvironment(macCatalyst) here
1821
@inline(__always)
1922
package func isCatalyst() -> Bool {
20-
#if os(iOS) || os(tvOS) || os(watchOS)
21-
false
22-
#elseif os(macOS)
23-
// NOTE: use runtime check instead of #if targetEnvironment(macCatalyst) here
23+
#if os(macOS) || targetEnvironment(macCatalyst)
2424
_CFMZEnabled()
2525
#else
2626
false
@@ -29,22 +29,20 @@ package func isCatalyst() -> Bool {
2929

3030
@inline(__always)
3131
package func isUIKitBased() -> Bool {
32-
#if os(iOS) || os(tvOS) || os(watchOS)
33-
true
34-
#elseif os(macOS)
32+
#if os(macOS) || targetEnvironment(macCatalyst)
3533
_CFMZEnabled()
3634
#else
37-
false
35+
true
3836
#endif
3937
}
4038

4139
@inline(__always)
4240
package func isAppKitBased() -> Bool {
43-
#if os(iOS) || os(tvOS) || os(watchOS)
44-
false
45-
#elseif os(macOS)
41+
#if os(macOS) || targetEnvironment(macCatalyst)
4642
!_CFMZEnabled()
4743
#else
4844
false
4945
#endif
5046
}
47+
48+
#endif

Tests/COpenSwiftUICoreTests/Shims/DyldPrivateTests.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,46 @@ struct DyldPrivateTests {
2222
if #unavailable(iOS 19) {
2323
#expect(dyld_program_sdk_at_least(.init(
2424
platform: dyld_get_active_platform(),
25-
version: DyldIOSVersion.V19_0.rawValue
25+
version: DYLD_IOS_VERSION._19_0.rawValue
2626
)) == false)
2727
if #unavailable(iOS 18) {
2828
#expect(dyld_program_sdk_at_least(.init(
2929
platform: dyld_get_active_platform(),
30-
version: DyldIOSVersion.V18_0.rawValue
30+
version: DYLD_IOS_VERSION._18_0.rawValue
3131
)) == false)
3232
} else {
3333
#expect(dyld_program_sdk_at_least(.init(
3434
platform: dyld_get_active_platform(),
35-
version: DyldIOSVersion.V18_0.rawValue
35+
version: DYLD_IOS_VERSION._18_0.rawValue
3636
)) == true)
3737
}
3838
} else {
3939
#expect(dyld_program_sdk_at_least(.init(
4040
platform: dyld_get_active_platform(),
41-
version: DyldIOSVersion.V19_0.rawValue
41+
version: DYLD_IOS_VERSION._19_0.rawValue
4242
)) == true)
4343
}
4444
#elseif os(macOS)
4545
if #unavailable(macOS 16) {
4646
#expect(dyld_program_sdk_at_least(.init(
4747
platform: dyld_get_active_platform(),
48-
version: DyldMacOSXVersion.V16_0.rawValue
48+
version: DYLD_MACOSX_VERSION._16_0.rawValue
4949
)) == false)
5050
if #unavailable(macOS 15) {
5151
#expect(dyld_program_sdk_at_least(.init(
5252
platform: dyld_get_active_platform(),
53-
version: DyldMacOSXVersion.V15_0.rawValue
53+
version: DYLD_MACOSX_VERSION._15_0.rawValue
5454
)) == false)
5555
} else {
5656
#expect(dyld_program_sdk_at_least(.init(
5757
platform: dyld_get_active_platform(),
58-
version: DyldMacOSXVersion.V15_0.rawValue
58+
version: DYLD_MACOSX_VERSION._15_0.rawValue
5959
)) == true)
6060
}
6161
} else {
6262
#expect(dyld_program_sdk_at_least(.init(
6363
platform: dyld_get_active_platform(),
64-
version: DyldMacOSXVersion.V16_0.rawValue
64+
version: DYLD_MACOSX_VERSION._16_0.rawValue
6565
)) == true)
6666
}
6767
#else
@@ -82,39 +82,39 @@ struct DyldPrivateTests {
8282

8383
@Test
8484
func activePlatform() throws {
85-
let platform = try #require(DyldPlatform(rawValue: dyld_get_active_platform()))
85+
let platform = try #require(DYLD_PLATFORM(rawValue: dyld_get_active_platform()))
8686
#if canImport(Darwin)
8787
#if targetEnvironment(macCatalyst)
88-
#expect(platform == .macCatalyst)
88+
#expect(platform == .MACCATALYST)
8989
#elseif targetEnvironment(simulator)
9090
#if os(iOS)
91-
#expect(platform == .iOSSimulator)
91+
#expect(platform == .IOSSIMULATOR)
9292
#elseif os(tvOS)
93-
#expect(platform == .tvOSSimulator)
93+
#expect(platform == .TVOSSIMULATOR)
9494
#elseif os(watchOS)
95-
#expect(platform == .watchOSSimulator)
95+
#expect(platform == .WATCHOSSIMULATOR)
9696
#elseif os(visionOS)
97-
#expect(platform == .xROSSimulator)
97+
#expect(platform == .XROS_SIMULATOR)
9898
#else
9999
fatalError("Unsupported Darwin simulator platform")
100100
#endif
101101
#else
102102
#if os(iOS)
103-
#expect(platform == .iOS)
103+
#expect(platform == .IOS)
104104
#elseif os(macOS)
105-
#expect(platform == .macOS)
105+
#expect(platform == .MACOS)
106106
#elseif os(tvOS)
107-
#expect(platform == .tvOS)
107+
#expect(platform == .TVOS)
108108
#elseif os(watchOS)
109-
#expect(platform == .watchOS)
109+
#expect(platform == .WATCHOS)
110110
#elseif os(visionOS)
111-
#expect(platform == .xROS)
111+
#expect(platform == .XROS)
112112
#else
113113
fatalError("Unsupported Darwin platform")
114114
#endif
115115
#endif
116116
#else
117-
#expect(platform == .unknown)
117+
#expect(platform == .UNKNOWN)
118118
#endif
119119
}
120120
}

0 commit comments

Comments
 (0)