Skip to content

Commit ca047c1

Browse files
authored
Add OPENRENDERBOX_CF_CGTYPE support (#17)
1 parent df71ed0 commit ca047c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+533
-24
lines changed

.github/workflows/ios.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ jobs:
3838
- name: Set up build environment
3939
run: Scripts/CI/darwin_setup_build.sh
4040
shell: bash
41-
- name: Build in debug mode on iOS
41+
- name: Build in debug mode on iOS Simulator
4242
run: |
4343
xcodebuild build \
4444
-scheme OpenRenderBox-Package \
4545
-configuration Debug \
4646
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
4747
-derivedDataPath .build-debug \
4848
-skipMacroValidation \
49-
-skipPackagePluginValidation \
50-
OTHER_SWIFT_FLAGS="-warnings-as-errors"
49+
-skipPackagePluginValidation
50+
# OTHER_SWIFT_FLAGS="-warnings-as-errors" Conflicting options '-warnings-as-errors' and '-suppress-warnings'
5151
- name: Build and run tests in debug mode with coverage on iOS Simulator
5252
run: |
5353
xcodebuild test \

AGENTS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# OpenRenderBox Agent Guidelines
2+
3+
## Preprocessor Definition Naming Conventions
4+
5+
- **C/C++ definitions**: Use `ORB_` prefix (e.g., `ORB_SWIFT_NAME`, `ORB_TARGET_OS_DARWIN`)
6+
- **Package.swift injected definitions**: Use `OPENRENDERBOX_` prefix (e.g., `OPENRENDERBOX_CF_CGTYPES`, `OPENRENDERBOX_RENDERBOX`)
7+

Package.resolved

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ let compatibilityTestCondition = envBoolValue("COMPATIBILITY_TEST", default: fal
155155
let useLocalDeps = envBoolValue("USE_LOCAL_DEPS")
156156
let renderBoxCondtion = envBoolValue("RENDERBOX", default: buildForDarwinPlatform && !isSPIBuild)
157157

158+
/// CGFloat and CGRect def in CFCGTypes.h will conflict with Foundation's CGSize/CGRect def on Linux.
159+
/// macOS: true -> no issue
160+
/// macOS: false -> use Swift implementation with OpenCoreGraphics Swift CGPath
161+
/// Linux: true + No CGPathRef support in ORBPath -> confilict with Foundation def
162+
/// Linux: false -> use Swift implementation with OpenCoreGraphics Swift CGPath
163+
let cfCGTypes = envBoolValue("CF_CGTYPES", default: buildForDarwinPlatform)
164+
158165
// MARK: - Shared Settings
159166

160167
var sharedCSettings: [CSetting] = [
@@ -176,6 +183,12 @@ if libraryEvolutionCondition {
176183
sharedSwiftSettings.append(.unsafeFlags(["-enable-library-evolution", "-no-verify-emitted-module-interface"]))
177184
}
178185

186+
if cfCGTypes {
187+
sharedCSettings.append(.define("OPENRENDERBOX_CF_CGTYPES"))
188+
sharedCxxSettings.append(.define("OPENRENDERBOX_CF_CGTYPES"))
189+
sharedSwiftSettings.append(.define("OPENRENDERBOX_CF_CGTYPES"))
190+
}
191+
179192
// MARK: - Extension
180193

181194
extension Target {
@@ -199,20 +212,34 @@ extension [Platform] {
199212

200213
let openRenderBoxTarget = Target.target(
201214
name: "OpenRenderBox",
215+
dependencies: [
216+
"OpenRenderBoxCxx",
217+
.product(name: "OpenCoreGraphicsShims", package: "OpenCoreGraphics"),
218+
],
219+
cSettings: sharedCSettings,
220+
cxxSettings: sharedCxxSettings,
221+
swiftSettings: sharedSwiftSettings
222+
)
223+
// FIXME: Merge into one target
224+
// OpenRenderBox is a C++ & Swift mix target.
225+
// The SwiftPM support for such usage is still in progress.
226+
let openRenderBoxCxxTarget = Target.target(
227+
name: "OpenRenderBoxCxx",
202228
cSettings: sharedCSettings,
203229
cxxSettings: sharedCxxSettings
204230
)
205231
let openRenderBoxShimsTarget = Target.target(
206232
name: "OpenRenderBoxShims",
207233
swiftSettings: sharedSwiftSettings
208234
)
209-
let openRenderBoxCxxTestTarget = Target.testTarget(
210-
name: "OpenRenderBoxCxxTests",
235+
let openRenderBoxTestsTarget = Target.testTarget(
236+
name: "OpenRenderBoxTests",
211237
dependencies: [
212238
"OpenRenderBox",
213239
],
214240
exclude: ["README.md"],
215241
cSettings: sharedCSettings + [.define("SWIFT_TESTING")],
242+
cxxSettings: sharedCxxSettings + [.define("SWIFT_TESTING")],
216243
swiftSettings: sharedSwiftSettings + [.interoperabilityMode(.Cxx)]
217244
)
218245
let openRenderBoxCompatibilityTestTarget = Target.testTarget(
@@ -221,6 +248,8 @@ let openRenderBoxCompatibilityTestTarget = Target.testTarget(
221248
.product(name: "RealModule", package: "swift-numerics"),
222249
],
223250
exclude: ["README.md"],
251+
cSettings: sharedCSettings + [.define("SWIFT_TESTING")],
252+
cxxSettings: sharedCxxSettings + [.define("SWIFT_TESTING")],
224253
swiftSettings: sharedSwiftSettings
225254
)
226255

@@ -239,35 +268,31 @@ default:
239268
let package = Package(
240269
name: "OpenRenderBox",
241270
products: [
242-
.library(name: "OpenRenderBox", type: libraryType, targets: ["OpenRenderBox"]),
271+
.library(name: "OpenRenderBox", type: libraryType, targets: ["OpenRenderBox", "OpenRenderBoxCxx"]),
243272
.library(name: "OpenRenderBoxShims", type: libraryType, targets: ["OpenRenderBoxShims"]),
244273
],
245274
dependencies: [
246-
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
275+
.package(url: "https://github.com/apple/swift-numerics", from: "1.1.1"),
247276
],
248277
targets: [
249278
openRenderBoxTarget,
279+
openRenderBoxCxxTarget,
250280
openRenderBoxShimsTarget,
251-
openRenderBoxCxxTestTarget,
281+
openRenderBoxTestsTarget,
252282
openRenderBoxCompatibilityTestTarget,
253283
],
254284
cxxLanguageStandard: .cxx20
255285
)
256286

257287
if renderBoxCondtion {
258-
let privateFrameworkRepo: Package.Dependency
259-
if useLocalDeps {
260-
privateFrameworkRepo = Package.Dependency.package(path: "../DarwinPrivateFrameworks")
261-
} else {
262-
privateFrameworkRepo = Package.Dependency.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main")
263-
}
264-
package.dependencies.append(privateFrameworkRepo)
265288
openRenderBoxShimsTarget.addRBSettings()
289+
}
266290

267-
let rbVersion = EnvManager.shared.withDomain("DarwinPrivateFrameworks") {
291+
if renderBoxCondtion {
292+
let release = EnvManager.shared.withDomain("DarwinPrivateFrameworks") {
268293
envIntValue("TARGET_RELEASE", default: 2024)
269294
}
270-
package.platforms = switch rbVersion {
295+
package.platforms = switch release {
271296
case 2024: [.iOS(.v18), .macOS(.v15), .macCatalyst(.v18), .tvOS(.v18), .watchOS(.v10), .visionOS(.v2)]
272297
case 2021: [.iOS(.v15), .macOS(.v12), .macCatalyst(.v15), .tvOS(.v15), .watchOS(.v7)]
273298
default: nil
@@ -276,6 +301,24 @@ if renderBoxCondtion {
276301
openRenderBoxShimsTarget.dependencies.append("OpenRenderBox")
277302
}
278303

304+
if useLocalDeps {
305+
var dependencies: [Package.Dependency] = [
306+
.package(path: "../OpenCoreGraphics"),
307+
]
308+
if renderBoxCondtion {
309+
dependencies.append(.package(path: "../DarwinPrivateFrameworks"))
310+
}
311+
package.dependencies += dependencies
312+
} else {
313+
var dependencies: [Package.Dependency] = [
314+
.package(url: "https://github.com/OpenSwiftUIProject/OpenCoreGraphics", branch: "main"),
315+
]
316+
if renderBoxCondtion {
317+
dependencies.append(.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main"))
318+
}
319+
package.dependencies += dependencies
320+
}
321+
279322
if compatibilityTestCondition && renderBoxCondtion {
280323
openRenderBoxCompatibilityTestTarget.addRBSettings()
281324
var swiftSettings: [SwiftSetting] = (openRenderBoxCompatibilityTestTarget.swiftSettings ?? [])

Scripts/CI/darwin_setup_build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ filepath() {
88
REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))"
99
cd $REPO_ROOT
1010

11+
Scripts/CI/opencoregraphics_setup.sh
1112
Scripts/CI/rb_setup.sh
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# A `realpath` alternative using the default C implementation.
4+
filepath() {
5+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
6+
}
7+
8+
REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))"
9+
10+
clone_checkout_opencoregraphics() {
11+
cd $REPO_ROOT
12+
revision=$(Scripts/CI/get_revision.sh opencoregraphics)
13+
cd ..
14+
if [ ! -d OpenCoreGraphics ]; then
15+
gh repo clone OpenSwiftUIProject/OpenCoreGraphics
16+
cd OpenCoreGraphics
17+
else
18+
echo "OpenCoreGraphics already exists, skipping clone."
19+
cd OpenCoreGraphics
20+
git fetch --all --quiet
21+
git stash --quiet || true
22+
git reset --hard --quiet origin/main
23+
fi
24+
git checkout --quiet $revision
25+
}
26+
27+
clone_checkout_opencoregraphics

Sources/OpenRenderBox/Export.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
// Export.swift
3+
// OpenRenderBox
4+
5+
@_exported public import OpenRenderBoxCxx
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
//
2+
// ORBPath.swift
3+
// OpenRenderBox
4+
5+
#if !OPENRENDERBOX_CF_CGTYPES
6+
public import OpenCoreGraphicsShims
7+
8+
public typealias ORBPathApplyCallback = (UnsafeMutableRawPointer, ORBPath.Element, UnsafePointer<CGFloat>, UnsafeRawPointer?) -> Bool
9+
10+
public struct ORBPath {
11+
public var storage: ORBPath.Storage
12+
public var callbacks: UnsafePointer<ORBPath.Callbacks>
13+
14+
public init(storage: ORBPath.Storage, callbacks: UnsafePointer<ORBPath.Callbacks>) {
15+
self.storage = storage
16+
self.callbacks = callbacks
17+
}
18+
}
19+
20+
// MARK: - Element
21+
22+
extension ORBPath {
23+
/// Path element type for path enumeration
24+
public enum Element: Int32, @unchecked Sendable {
25+
case moveToPoint = 0
26+
case addLineToPoint = 1
27+
case addQuadCurveToPoint = 2
28+
case addCurveToPoint = 3
29+
case closeSubpath = 4
30+
case rect = 5
31+
case roundedRect = 6
32+
case fixedRoundedRectCircular = 8
33+
case fixedRoundedRectContinuous = 9
34+
case invalid = 25
35+
}
36+
}
37+
38+
// MARK: - RoundedCornerStyle
39+
40+
extension ORBPath {
41+
/// Defines the shape of a rounded rectangle's corners.
42+
public enum RoundedCornerStyle: Int32, @unchecked Sendable {
43+
/// Quarter-circle rounded rect corners.
44+
case circular = 0
45+
/// Continuous curvature rounded rect corners.
46+
case continuous = 1
47+
}
48+
}
49+
50+
// MARK: - Storage
51+
52+
extension ORBPath {
53+
public struct Storage: Hashable, Equatable, RawRepresentable, @unchecked Sendable {
54+
public var rawValue: OpaquePointer
55+
56+
public init(_ rawValue: OpaquePointer) {
57+
self.rawValue = rawValue
58+
}
59+
60+
public init(rawValue: OpaquePointer) {
61+
self.rawValue = rawValue
62+
}
63+
}
64+
}
65+
66+
// MARK: - Static Properties
67+
68+
extension ORBPath {
69+
/// Global empty path (storage = null, callbacks = &ORBPathEmptyCallbacks)
70+
public static var empty: ORBPath {
71+
_openRenderBoxUnimplementedFailure()
72+
}
73+
74+
/// Global null path (storage = 0x1, callbacks = &ORBPathEmptyCallbacks)
75+
public static var null: ORBPath {
76+
_openRenderBoxUnimplementedFailure()
77+
}
78+
}
79+
80+
// MARK: - Memory Management
81+
82+
extension ORBPath {
83+
public func retain() {
84+
_openRenderBoxUnimplementedFailure()
85+
}
86+
87+
public func release() {
88+
_openRenderBoxUnimplementedFailure()
89+
}
90+
}
91+
92+
// MARK: - Initializers
93+
94+
extension ORBPath {
95+
public init(cgPath: CGPath) {
96+
_openRenderBoxUnimplementedFailure()
97+
}
98+
99+
public init(rect: CGRect, transform: UnsafePointer<CGAffineTransform>?) {
100+
_openRenderBoxUnimplementedFailure()
101+
}
102+
103+
public init(ellipseIn rect: CGRect, transform: UnsafePointer<CGAffineTransform>?) {
104+
_openRenderBoxUnimplementedFailure()
105+
}
106+
107+
public init(roundedRect rect: CGRect, cornerWidth: CGFloat, cornerHeight: CGFloat, style: ORBPath.RoundedCornerStyle, transform: UnsafePointer<CGAffineTransform>?) {
108+
_openRenderBoxUnimplementedFailure()
109+
}
110+
111+
public init(roundedRect rect: CGRect, topLeftRadius: CGFloat, bottomLeftRadius: CGFloat, bottomRightRadius: CGFloat, topRightRadius: CGFloat, style: ORBPath.RoundedCornerStyle, transform: UnsafePointer<CGAffineTransform>?) {
112+
_openRenderBoxUnimplementedFailure()
113+
}
114+
}
115+
116+
// MARK: - Properties
117+
118+
extension ORBPath {
119+
public var isEmpty: Bool {
120+
_openRenderBoxUnimplementedFailure()
121+
}
122+
123+
public var cgPath: CGPath {
124+
_openRenderBoxUnimplementedFailure()
125+
}
126+
}
127+
128+
// MARK: - Methods
129+
130+
extension ORBPath {
131+
public func apply(info: UnsafeMutableRawPointer, callback: ORBPathApplyCallback?) -> Bool {
132+
_openRenderBoxUnimplementedFailure()
133+
}
134+
135+
public func isEqual(to rhs: ORBPath) -> Bool {
136+
_openRenderBoxUnimplementedFailure()
137+
}
138+
139+
public func contains(point: CGPoint, eoFill: Bool) -> Bool {
140+
_openRenderBoxUnimplementedFailure()
141+
}
142+
143+
public func containsPoints(count: UInt64, points: UnsafePointer<CGPoint>, eoFill: Bool, transform: UnsafePointer<CGAffineTransform>?) -> Bool {
144+
_openRenderBoxUnimplementedFailure()
145+
}
146+
}
147+
148+
#endif
149+

0 commit comments

Comments
 (0)