Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ jobs:
- name: Set up build environment
run: Scripts/CI/darwin_setup_build.sh
shell: bash
- name: Build in debug mode on iOS
- name: Build in debug mode on iOS Simulator
run: |
xcodebuild build \
-scheme OpenRenderBox-Package \
-configuration Debug \
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
-derivedDataPath .build-debug \
-skipMacroValidation \
-skipPackagePluginValidation \
OTHER_SWIFT_FLAGS="-warnings-as-errors"
-skipPackagePluginValidation
# OTHER_SWIFT_FLAGS="-warnings-as-errors" Conflicting options '-warnings-as-errors' and '-suppress-warnings'
- name: Build and run tests in debug mode with coverage on iOS Simulator
run: |
xcodebuild test \
Expand Down
7 changes: 7 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OpenRenderBox Agent Guidelines

## Preprocessor Definition Naming Conventions

- **C/C++ definitions**: Use `ORB_` prefix (e.g., `ORB_SWIFT_NAME`, `ORB_TARGET_OS_DARWIN`)
- **Package.swift injected definitions**: Use `OPENRENDERBOX_` prefix (e.g., `OPENRENDERBOX_CF_CGTYPES`, `OPENRENDERBOX_RENDERBOX`)

13 changes: 11 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 57 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ let compatibilityTestCondition = envBoolValue("COMPATIBILITY_TEST", default: fal
let useLocalDeps = envBoolValue("USE_LOCAL_DEPS")
let renderBoxCondtion = envBoolValue("RENDERBOX", default: buildForDarwinPlatform && !isSPIBuild)

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

// MARK: - Shared Settings

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

if cfCGTypes {
sharedCSettings.append(.define("OPENRENDERBOX_CF_CGTYPES"))
sharedCxxSettings.append(.define("OPENRENDERBOX_CF_CGTYPES"))
sharedSwiftSettings.append(.define("OPENRENDERBOX_CF_CGTYPES"))
}

// MARK: - Extension

extension Target {
Expand All @@ -199,20 +212,34 @@ extension [Platform] {

let openRenderBoxTarget = Target.target(
name: "OpenRenderBox",
dependencies: [
"OpenRenderBoxCxx",
.product(name: "OpenCoreGraphicsShims", package: "OpenCoreGraphics"),
],
cSettings: sharedCSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings
)
// FIXME: Merge into one target
// OpenRenderBox is a C++ & Swift mix target.
// The SwiftPM support for such usage is still in progress.
let openRenderBoxCxxTarget = Target.target(
name: "OpenRenderBoxCxx",
cSettings: sharedCSettings,
cxxSettings: sharedCxxSettings
)
let openRenderBoxShimsTarget = Target.target(
name: "OpenRenderBoxShims",
swiftSettings: sharedSwiftSettings
)
let openRenderBoxCxxTestTarget = Target.testTarget(
name: "OpenRenderBoxCxxTests",
let openRenderBoxTestsTarget = Target.testTarget(
name: "OpenRenderBoxTests",
dependencies: [
"OpenRenderBox",
],
exclude: ["README.md"],
cSettings: sharedCSettings + [.define("SWIFT_TESTING")],
cxxSettings: sharedCxxSettings + [.define("SWIFT_TESTING")],
swiftSettings: sharedSwiftSettings + [.interoperabilityMode(.Cxx)]
)
let openRenderBoxCompatibilityTestTarget = Target.testTarget(
Expand All @@ -221,6 +248,8 @@ let openRenderBoxCompatibilityTestTarget = Target.testTarget(
.product(name: "RealModule", package: "swift-numerics"),
],
exclude: ["README.md"],
cSettings: sharedCSettings + [.define("SWIFT_TESTING")],
cxxSettings: sharedCxxSettings + [.define("SWIFT_TESTING")],
swiftSettings: sharedSwiftSettings
)

Expand All @@ -239,35 +268,31 @@ default:
let package = Package(
name: "OpenRenderBox",
products: [
.library(name: "OpenRenderBox", type: libraryType, targets: ["OpenRenderBox"]),
.library(name: "OpenRenderBox", type: libraryType, targets: ["OpenRenderBox", "OpenRenderBoxCxx"]),
.library(name: "OpenRenderBoxShims", type: libraryType, targets: ["OpenRenderBoxShims"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
.package(url: "https://github.com/apple/swift-numerics", from: "1.1.1"),
],
targets: [
openRenderBoxTarget,
openRenderBoxCxxTarget,
openRenderBoxShimsTarget,
openRenderBoxCxxTestTarget,
openRenderBoxTestsTarget,
openRenderBoxCompatibilityTestTarget,
],
cxxLanguageStandard: .cxx20
)

if renderBoxCondtion {
let privateFrameworkRepo: Package.Dependency
if useLocalDeps {
privateFrameworkRepo = Package.Dependency.package(path: "../DarwinPrivateFrameworks")
} else {
privateFrameworkRepo = Package.Dependency.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main")
}
package.dependencies.append(privateFrameworkRepo)
openRenderBoxShimsTarget.addRBSettings()
}

let rbVersion = EnvManager.shared.withDomain("DarwinPrivateFrameworks") {
if renderBoxCondtion {
let release = EnvManager.shared.withDomain("DarwinPrivateFrameworks") {
envIntValue("TARGET_RELEASE", default: 2024)
}
package.platforms = switch rbVersion {
package.platforms = switch release {
case 2024: [.iOS(.v18), .macOS(.v15), .macCatalyst(.v18), .tvOS(.v18), .watchOS(.v10), .visionOS(.v2)]
case 2021: [.iOS(.v15), .macOS(.v12), .macCatalyst(.v15), .tvOS(.v15), .watchOS(.v7)]
default: nil
Expand All @@ -276,6 +301,24 @@ if renderBoxCondtion {
openRenderBoxShimsTarget.dependencies.append("OpenRenderBox")
}

if useLocalDeps {
var dependencies: [Package.Dependency] = [
.package(path: "../OpenCoreGraphics"),
]
if renderBoxCondtion {
dependencies.append(.package(path: "../DarwinPrivateFrameworks"))
}
package.dependencies += dependencies
} else {
var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/OpenSwiftUIProject/OpenCoreGraphics", branch: "main"),
]
if renderBoxCondtion {
dependencies.append(.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main"))
}
package.dependencies += dependencies
}

if compatibilityTestCondition && renderBoxCondtion {
openRenderBoxCompatibilityTestTarget.addRBSettings()
var swiftSettings: [SwiftSetting] = (openRenderBoxCompatibilityTestTarget.swiftSettings ?? [])
Expand Down
1 change: 1 addition & 0 deletions Scripts/CI/darwin_setup_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ filepath() {
REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))"
cd $REPO_ROOT

Scripts/CI/opencoregraphics_setup.sh
Scripts/CI/rb_setup.sh
27 changes: 27 additions & 0 deletions Scripts/CI/opencoregraphics_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# A `realpath` alternative using the default C implementation.
filepath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))"

clone_checkout_opencoregraphics() {
cd $REPO_ROOT
revision=$(Scripts/CI/get_revision.sh opencoregraphics)
cd ..
if [ ! -d OpenCoreGraphics ]; then
gh repo clone OpenSwiftUIProject/OpenCoreGraphics
cd OpenCoreGraphics
else
echo "OpenCoreGraphics already exists, skipping clone."
cd OpenCoreGraphics
git fetch --all --quiet
git stash --quiet || true
git reset --hard --quiet origin/main
fi
git checkout --quiet $revision
}

clone_checkout_opencoregraphics
5 changes: 5 additions & 0 deletions Sources/OpenRenderBox/Export.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Export.swift
// OpenRenderBox

@_exported public import OpenRenderBoxCxx
149 changes: 149 additions & 0 deletions Sources/OpenRenderBox/Path/ORBPath.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//
// ORBPath.swift
// OpenRenderBox

#if !OPENRENDERBOX_CF_CGTYPES
public import OpenCoreGraphicsShims

public typealias ORBPathApplyCallback = (UnsafeMutableRawPointer, ORBPath.Element, UnsafePointer<CGFloat>, UnsafeRawPointer?) -> Bool

public struct ORBPath {
public var storage: ORBPath.Storage
public var callbacks: UnsafePointer<ORBPath.Callbacks>

public init(storage: ORBPath.Storage, callbacks: UnsafePointer<ORBPath.Callbacks>) {
self.storage = storage
self.callbacks = callbacks
}
}

// MARK: - Element

extension ORBPath {
/// Path element type for path enumeration
public enum Element: Int32, @unchecked Sendable {
case moveToPoint = 0
case addLineToPoint = 1
case addQuadCurveToPoint = 2
case addCurveToPoint = 3
case closeSubpath = 4
case rect = 5
case roundedRect = 6
case fixedRoundedRectCircular = 8
case fixedRoundedRectContinuous = 9
case invalid = 25
}
}

// MARK: - RoundedCornerStyle

extension ORBPath {
/// Defines the shape of a rounded rectangle's corners.
public enum RoundedCornerStyle: Int32, @unchecked Sendable {
/// Quarter-circle rounded rect corners.
case circular = 0
/// Continuous curvature rounded rect corners.
case continuous = 1
}
}

// MARK: - Storage

extension ORBPath {
public struct Storage: Hashable, Equatable, RawRepresentable, @unchecked Sendable {
public var rawValue: OpaquePointer

public init(_ rawValue: OpaquePointer) {
self.rawValue = rawValue
}

public init(rawValue: OpaquePointer) {
self.rawValue = rawValue
}
}
}

// MARK: - Static Properties

extension ORBPath {
/// Global empty path (storage = null, callbacks = &ORBPathEmptyCallbacks)
public static var empty: ORBPath {
_openRenderBoxUnimplementedFailure()
}

/// Global null path (storage = 0x1, callbacks = &ORBPathEmptyCallbacks)
public static var null: ORBPath {
_openRenderBoxUnimplementedFailure()
}
}

// MARK: - Memory Management

extension ORBPath {
public func retain() {
_openRenderBoxUnimplementedFailure()
}

public func release() {
_openRenderBoxUnimplementedFailure()
}
}

// MARK: - Initializers

extension ORBPath {
public init(cgPath: CGPath) {
_openRenderBoxUnimplementedFailure()
}

public init(rect: CGRect, transform: UnsafePointer<CGAffineTransform>?) {
_openRenderBoxUnimplementedFailure()
}

public init(ellipseIn rect: CGRect, transform: UnsafePointer<CGAffineTransform>?) {
_openRenderBoxUnimplementedFailure()
}

public init(roundedRect rect: CGRect, cornerWidth: CGFloat, cornerHeight: CGFloat, style: ORBPath.RoundedCornerStyle, transform: UnsafePointer<CGAffineTransform>?) {
_openRenderBoxUnimplementedFailure()
}

public init(roundedRect rect: CGRect, topLeftRadius: CGFloat, bottomLeftRadius: CGFloat, bottomRightRadius: CGFloat, topRightRadius: CGFloat, style: ORBPath.RoundedCornerStyle, transform: UnsafePointer<CGAffineTransform>?) {
_openRenderBoxUnimplementedFailure()
}
}

// MARK: - Properties

extension ORBPath {
public var isEmpty: Bool {
_openRenderBoxUnimplementedFailure()
}

public var cgPath: CGPath {
_openRenderBoxUnimplementedFailure()
}
}

// MARK: - Methods

extension ORBPath {
public func apply(info: UnsafeMutableRawPointer, callback: ORBPathApplyCallback?) -> Bool {
_openRenderBoxUnimplementedFailure()
}

public func isEqual(to rhs: ORBPath) -> Bool {
_openRenderBoxUnimplementedFailure()
}

public func contains(point: CGPoint, eoFill: Bool) -> Bool {
_openRenderBoxUnimplementedFailure()
}

public func containsPoints(count: UInt64, points: UnsafePointer<CGPoint>, eoFill: Bool, transform: UnsafePointer<CGAffineTransform>?) -> Bool {
_openRenderBoxUnimplementedFailure()
}
}

#endif

Loading