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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
## 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`)
- **Package.swift injected definitions**: Use `OPENRENDERBOX_` prefix (e.g., `OPENRENDERBOX_RENDERBOX`)

2 changes: 1 addition & 1 deletion Package.resolved

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

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

// C geometry types conflict with Foundation's Swift geometry types on Linux.
// Disable this flag to use Swift Path instead of the C++ implementation.
let cfCGTypes = envBoolValue("CF_CGTYPES", default: buildForDarwinPlatform)
// Use OPENSWIFTUI_COREGRAPHICS to select the same backend in ORB and OCG shims.
let coreGraphicsCondition = envBoolValue("COREGRAPHICS", default: buildForDarwinPlatform)

// MARK: - Shared Settings

var sharedCSettings: [CSetting] = [
let sharedCSettings: [CSetting] = [
.unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)),
// .unsafeFlags(["-fmodules"]),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
]
var sharedCxxSettings: [CXXSetting] = [
let sharedCxxSettings: [CXXSetting] = [
.unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)),
// .unsafeFlags(["-fcxx-modules"]),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
Expand All @@ -183,12 +180,6 @@ 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"))
}

if coreGraphicsCondition {
sharedSwiftSettings.append(.define("OPENRENDERBOX_COREGRAPHICS"))
}
Expand Down
23 changes: 1 addition & 22 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let moduleHeaders = sourceModuleMap.components(separatedBy: .newlines).compactMa
// Use the same module declarations for SwiftPM and the framework.
let frameworkModuleMap = "framework " + sourceModuleMap
.replacingOccurrences(of: "module OpenRenderBoxCxx", with: "module OpenRenderBox")
.replacingOccurrences(of: "module OpenRenderBox.C {", with: "module OpenRenderBox.C {\n header \"ORBConfiguration.h\"")
.replacingOccurrences(of: "header \"OpenRenderBox/", with: "header \"")
.replacingOccurrences(of: "header \"../", with: "header \"")
let moduleMapDirectory = root.appendingPathComponent("Derived/ModuleMaps")
Expand All @@ -26,19 +25,6 @@ try frameworkModuleMap.write(
encoding: .utf8
)

// Consumers must use the same backend as the framework binary.
let frameworkConfiguration = """
#pragma once

#if defined(OPENRENDERBOX_CF_CGTYPES) && OPENRENDERBOX_CF_CGTYPES != 1
#error "This OpenRenderBox framework requires OPENRENDERBOX_CF_CGTYPES=1."
#endif
#ifndef OPENRENDERBOX_CF_CGTYPES
#define OPENRENDERBOX_CF_CGTYPES 1
#endif

"""

// Preserve feature paths for the C++ and Objective-C submodules.
let internalHeaders = moduleHeaders.filter { $0.hasPrefix("../") }.map { String($0.dropFirst(3)) }
// Tuist otherwise treats template headers as resources and adds a resource bundle.
Expand All @@ -53,16 +39,11 @@ let headerCopyCommands = internalHeaders.map { header in
let exportModuleHeaders = TargetScript.pre(
script: """
set -eu
mkdir -p "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
cat > "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/ORBConfiguration.h" <<'EOF'
\(frameworkConfiguration)
EOF
\(headerCopyCommands)
""",
name: "Export module headers",
inputPaths: internalHeaders.map { .glob(.path("\(sourceRoot)/\($0)")) },
outputPaths: [.path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/ORBConfiguration.h")]
+ internalHeaders.map { .path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/\($0)") },
outputPaths: internalHeaders.map { .path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/\($0)") },
basedOnDependencyAnalysis: true
)

Expand All @@ -75,8 +56,6 @@ let project = Project(
name: "OpenRenderBox",
settings: .settings(base: [
"CLANG_CXX_LANGUAGE_STANDARD": "c++20",
"GCC_PREPROCESSOR_DEFINITIONS": ["$(inherited)", "OPENRENDERBOX_CF_CGTYPES"],
"SWIFT_ACTIVE_COMPILATION_CONDITIONS": ["$(inherited)", "OPENRENDERBOX_CF_CGTYPES"],
"SWIFT_VERSION": "5.0",
]),
targets: [
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ Currently, this project is in early development.
The current suggested toolchain to build the project is Swift 6.3.3 / Xcode 26.6.

Tuist builds `OpenRenderBoxCxx` as a static library and links it into the dynamic
`OpenRenderBox.framework`. This build uses the Darwin SDK's CoreGraphics types.
Use SwiftPM for the other backend configurations.
`OpenRenderBox.framework`.

Path uses the C++ implementation and the SDK's CoreGraphics types on Apple
platforms. It uses the Swift implementation on other platforms.

```sh
tuist generate run --no-open --cache-profile none
Expand All @@ -37,9 +39,6 @@ Scripts/Tests/framework-test .build/tuist-framework/Build/Products/Release/OpenR
The framework contains the public C headers and the C++, Objective-C, and Swift
modules. The client test uses a separate copy of the bundle with no source search
paths and compiles the Swift interface.
The framework exports `ORBConfiguration.h` with its fixed CoreGraphics backend
setting. Consumers can use its path APIs without extra compiler definitions.
SwiftPM continues to select the backend with `OPENRENDERBOX_CF_CGTYPES`.

## Source Layout

Expand Down Expand Up @@ -83,7 +82,8 @@ Run the helper tests with `Scripts/Tests/add-header-test`.

## Shims

The `OpenRenderBoxShims` product provides Swift aliases and a C header for path APIs.
The `OpenRenderBoxShims` product provides Swift aliases for Path APIs. Its C
header exposes Path APIs on Apple platforms.
Swift clients use:

```swift
Expand Down
12 changes: 4 additions & 8 deletions Scripts/Tests/framework-test
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ EOF

cat > client.swift <<'EOF'
import OpenRenderBox
import OpenRenderBox.ObjC

precondition(ORBColor.black.alpha == 1)
precondition(ORBPath.empty.isEmpty)
Expand All @@ -96,21 +97,16 @@ EOF

target="$(uname -m)-apple-macos15.0"
common=(-target "$target" -F "$test_root" -framework OpenRenderBox -Wl,-rpath,"$test_root")
# Each guarded header must expose its API without another header setting the backend first.
for declaration in CFCGTypes.h:CGFloat ORBPath.h:ORBPath ORBPathCallbacks.h:ORBPathCallbacks ORBPathStorage.h:ORBPathStorageRef; do
# Check the public headers independently of include order.
for declaration in CFCGTypes.h:CGFloat CFCGTypes.h:CGSize CFCGTypes.h:CGPoint CFCGTypes.h:CGRect \
ORBPath.h:ORBPath ORBPathCallbacks.h:ORBPathCallbacks ORBPathStorage.h:ORBPathStorageRef; do
printf '#include <OpenRenderBox/%s>\n%s value;\n' "${declaration%:*}" "${declaration#*:}" > path-header.c
xcrun clang -target "$target" -F "$test_root" -fsyntax-only path-header.c
done
for declaration in Path/Storage.hpp:ORB::Path::Storage Path/NestedCallbacks.hpp:ORB::Path::NestedCallbacks; do
printf '#include <OpenRenderBox/%s>\nstatic_assert(sizeof(%s) > 0);\n' "${declaration%%:*}" "${declaration#*:}" > path-header.cpp
xcrun clang++ -target "$target" -F "$test_root" -std=c++20 -fsyntax-only path-header.cpp
done
if xcrun clang -target "$target" -F "$test_root" -DOPENRENDERBOX_CF_CGTYPES=0 \
-fsyntax-only path-header.c > backend-conflict.log 2>&1; then
echo "The framework must reject a conflicting backend setting." >&2
exit 1
fi
grep -Fq 'requires OPENRENDERBOX_CF_CGTYPES=1' backend-conflict.log
xcrun clang "${common[@]}" client.c -o client-c
./client-c
xcrun clang++ "${common[@]}" -std=c++20 client.cpp -o client-cxx
Expand Down
9 changes: 1 addition & 8 deletions Sources/OpenRenderBox/Animation/ORBSymbolUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
// ORBSymbolUpdate.swift
// OpenRenderBox

#if !canImport(ObjectiveC) || !OPENRENDERBOX_CF_CGTYPES
#if !canImport(ObjectiveC)
public import OpenCoreGraphicsShims
public import OpenRenderBoxCxx.C
#endif

#if !canImport(ObjectiveC)

extension ORBSymbolUpdate {
public var nextTime: Double { .infinity }
Expand All @@ -30,11 +27,7 @@ extension ORBSymbolUpdateLayer {
public var defaultColor: CGColor? { nil }

public func draw(in state: ORBDrawingState, color: ORBColor, opacity: Float, blendMode: ORBBlendMode, flags: ORBSymbolUpdateLayerFlags) {}
}
#endif

#if !canImport(ObjectiveC) || !OPENRENDERBOX_CF_CGTYPES
extension ORBSymbolUpdateLayer {
public func path(transform: UnsafeMutablePointer<CGAffineTransform>, flags: ORBSymbolUpdateLayerFlags) -> ORBPath {
transform.pointee = .identity
return .null
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenRenderBox/Path/ORBPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ORBPath.swift
// OpenRenderBox

#if !OPENRENDERBOX_CF_CGTYPES
#if !canImport(Darwin)
public import OpenCoreGraphicsShims

public typealias ORBPathApplyCallback = (UnsafeMutableRawPointer, ORBPath.Element, UnsafePointer<CGFloat>, UnsafeRawPointer?) -> Bool
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenRenderBox/Path/ORBPathCFData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ORBPathCFData.swift
// OpenRenderBox

#if !OPENRENDERBOX_CF_CGTYPES
#if !canImport(Darwin)
public import CoreFoundation

extension ORBPath {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenRenderBox/Path/ORBPathCallbacks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ORBPathCallbacks.swift
// OpenRenderBox

#if !OPENRENDERBOX_CF_CGTYPES
#if !canImport(Darwin)
public import OpenCoreGraphicsShims

// MARK: - ORBPath.CallbacksFlags
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenRenderBox/Path/ORBPathData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ORBPathData.swift
// OpenRenderBox

#if !OPENRENDERBOX_CF_CGTYPES
#if !canImport(Darwin)
import OpenCoreGraphicsShims

private typealias _ORBCGFloat = CGFloat
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenRenderBox/Path/ORBPathGeometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ORBPathGeometry.swift
// OpenRenderBox

#if !OPENRENDERBOX_CF_CGTYPES
#if !canImport(Darwin)
import Foundation
import OpenCoreGraphicsShims

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenRenderBox/Path/ORBPathStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ORBPathStorage.swift
// OpenRenderBox

#if !OPENRENDERBOX_CF_CGTYPES
#if !canImport(Darwin)
public import OpenCoreGraphicsShims

extension ORBPath.Storage {
Expand Down
2 changes: 0 additions & 2 deletions Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ ORB_EXPORT ORBSymbolStyle ORBSymbolUpdateLayerStyle(ORBSymbolUpdateLayer layer)
ORB_EXPORT NSString * _Nullable ORBSymbolUpdateLayerColorName(ORBSymbolUpdateLayer layer) ORB_SWIFT_NAME(getter:ORBSymbolUpdateLayer.colorName(self:));
ORB_EXPORT CGColorRef _Nullable ORBSymbolUpdateLayerDefaultColor(ORBSymbolUpdateLayer layer) CF_RETURNS_NOT_RETAINED ORB_SWIFT_NAME(getter:ORBSymbolUpdateLayer.defaultColor(self:));
// The update owns the returned path. Copy it before the update ends.
#if OPENRENDERBOX_CF_CGTYPES
ORB_EXPORT ORBPath ORBSymbolUpdateLayerPath(ORBSymbolUpdateLayer layer, CGAffineTransform *transform, ORBSymbolUpdateLayerFlags flags) ORB_SWIFT_NAME(ORBSymbolUpdateLayer.path(self:transform:flags:));
#endif
ORB_EXPORT void ORBSymbolUpdateLayerDraw(ORBSymbolUpdateLayer layer, ORBDrawingState state, ORBColor color, float opacity, ORBBlendMode blendMode, ORBSymbolUpdateLayerFlags flags) ORB_SWIFT_NAME(ORBSymbolUpdateLayer.draw(self:in:color:opacity:blendMode:flags:));

ORB_EXTERN_C_END
Expand Down
5 changes: 3 additions & 2 deletions Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

#if ORB_OBJC_FOUNDATION

#include <CoreGraphics/CoreGraphics.h>
#include <Foundation/Foundation.h>
#include <math.h>
#include <stdint.h>

// Symbol updates are placeholders until the symbol renderer is implemented.
double ORBSymbolUpdateNextTime(ORBSymbolUpdate update) { return INFINITY; }
Expand All @@ -19,12 +22,10 @@ void ORBSymbolUpdateDrawWithStyleResolver(ORBSymbolUpdate update, ORBDrawingStat
ORBSymbolStyle ORBSymbolUpdateLayerStyle(ORBSymbolUpdateLayer layer) { return ORBSymbolStylePrimary; }
NSString *ORBSymbolUpdateLayerColorName(ORBSymbolUpdateLayer layer) { return nil; }
CGColorRef ORBSymbolUpdateLayerDefaultColor(ORBSymbolUpdateLayer layer) { return NULL; }
#if OPENRENDERBOX_CF_CGTYPES
ORBPath ORBSymbolUpdateLayerPath(ORBSymbolUpdateLayer layer, CGAffineTransform *transform, ORBSymbolUpdateLayerFlags flags) {
*transform = CGAffineTransformIdentity;
return ORBPathNull;
}
#endif
void ORBSymbolUpdateLayerDraw(ORBSymbolUpdateLayer layer, ORBDrawingState state, ORBColor color, float opacity, ORBBlendMode blendMode, ORBSymbolUpdateLayerFlags flags) {}

#endif /* ORB_OBJC_FOUNDATION */
Loading
Loading