Skip to content

Commit 7c8778e

Browse files
authored
Update OpenRenderBox folder structure and add utilities (#10)
1 parent a288f58 commit 7c8778e

File tree

28 files changed

+352
-92
lines changed

28 files changed

+352
-92
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ DerivedData/
66
.swiftpm/configuration/registries.json
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.netrc
9+
.claude/
10+
.rb_template/

.spi.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version: 1
22
builder:
33
configs:
4-
- swift_version: 6.0
5-
documentation_targets: [OpenRenderBox]
4+
- documentation_targets: [OpenRenderBox]

Package.resolved

Lines changed: 2 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: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.0
1+
// swift-tools-version: 6.1
22

33
import Foundation
44
import PackageDescription
@@ -66,24 +66,25 @@ if libraryEvolutionCondition {
6666

6767
// MARK: - Targets
6868

69-
let openBoxTarget = Target.target(
69+
let openRenderBoxTarget = Target.target(
7070
name: "OpenRenderBox",
7171
cSettings: sharedCSettings,
7272
cxxSettings: sharedCxxSettings
7373
)
74-
let openBoxShimsTarget = Target.target(
74+
let openRenderBoxShimsTarget = Target.target(
7575
name: "OpenRenderBoxShims",
7676
swiftSettings: sharedSwiftSettings
7777
)
78-
let openBoxTestTarget = Target.testTarget(
79-
name: "OpenRenderBoxTests",
78+
let openRenderBoxCxxTestTarget = Target.testTarget(
79+
name: "OpenRenderBoxCxxTests",
8080
dependencies: [
8181
"OpenRenderBox",
8282
],
8383
exclude: ["README.md"],
84-
swiftSettings: sharedSwiftSettings
84+
cSettings: sharedCSettings + [.define("SWIFT_TESTING")],
85+
swiftSettings: sharedSwiftSettings + [.interoperabilityMode(.Cxx)]
8586
)
86-
let openBoxCompatibilityTestTarget = Target.testTarget(
87+
let openRenderBoxCompatibilityTestTarget = Target.testTarget(
8788
name: "OpenRenderBoxCompatibilityTests",
8889
dependencies: [
8990
.product(name: "RealModule", package: "swift-numerics"),
@@ -114,11 +115,10 @@ let package = Package(
114115
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
115116
],
116117
targets: [
117-
openBoxTarget,
118-
openBoxShimsTarget,
119-
120-
openBoxTestTarget,
121-
openBoxCompatibilityTestTarget,
118+
openRenderBoxTarget,
119+
openRenderBoxShimsTarget,
120+
openRenderBoxCxxTestTarget,
121+
openRenderBoxCompatibilityTestTarget,
122122
],
123123
cxxLanguageStandard: .cxx20
124124
)
@@ -135,34 +135,32 @@ if renderBoxCondtion {
135135
privateFrameworkRepo = Package.Dependency.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main")
136136
}
137137
package.dependencies.append(privateFrameworkRepo)
138-
var swiftSettings: [SwiftSetting] = (openBoxShimsTarget.swiftSettings ?? [])
138+
var swiftSettings: [SwiftSetting] = (openRenderBoxShimsTarget.swiftSettings ?? [])
139139
swiftSettings.append(.define("OPENRENDERBOX_RENDERBOX"))
140-
openBoxShimsTarget.swiftSettings = swiftSettings
141-
openBoxShimsTarget.dependencies.append(
140+
openRenderBoxShimsTarget.swiftSettings = swiftSettings
141+
openRenderBoxShimsTarget.dependencies.append(
142142
.product(name: "RenderBox", package: "DarwinPrivateFrameworks")
143143
)
144-
145144
let rbVersion = Context.environment["DARWIN_PRIVATE_FRAMEWORKS_TARGET_RELEASE"].flatMap { Int($0) } ?? 2024
146145
package.platforms = switch rbVersion {
147146
case 2024: [.iOS(.v18), .macOS(.v15), .macCatalyst(.v18), .tvOS(.v18), .watchOS(.v10), .visionOS(.v2)]
148147
case 2021: [.iOS(.v15), .macOS(.v12), .macCatalyst(.v15), .tvOS(.v15), .watchOS(.v7)]
149148
default: nil
150149
}
151150
} else {
152-
openBoxShimsTarget.dependencies.append("OpenRenderBox")
151+
openRenderBoxShimsTarget.dependencies.append("OpenRenderBox")
153152
}
154153

155154
let compatibilityTestCondition = envEnable("OPENRENDERBOX_COMPATIBILITY_TEST")
156155
if compatibilityTestCondition && renderBoxCondtion {
157-
openBoxCompatibilityTestTarget.dependencies.append(
156+
openRenderBoxCompatibilityTestTarget.dependencies.append(
158157
.product(name: "RenderBox", package: "DarwinPrivateFrameworks")
159158
)
160-
161-
var swiftSettings: [SwiftSetting] = (openBoxCompatibilityTestTarget.swiftSettings ?? [])
159+
var swiftSettings: [SwiftSetting] = (openRenderBoxCompatibilityTestTarget.swiftSettings ?? [])
162160
swiftSettings.append(.define("OPENRENDERBOX_COMPATIBILITY_TEST"))
163-
openBoxCompatibilityTestTarget.swiftSettings = swiftSettings
161+
openRenderBoxCompatibilityTestTarget.swiftSettings = swiftSettings
164162
} else {
165-
openBoxCompatibilityTestTarget.dependencies.append("OpenRenderBox")
163+
openRenderBoxCompatibilityTestTarget.dependencies.append("OpenRenderBox")
166164
}
167165

168166
extension [Platform] {

Scripts/bump_rb_pr.sh

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/bin/zsh
2+
3+
set -e
4+
5+
# A `realpath` alternative using the default C implementation.
6+
filepath() {
7+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
8+
}
9+
10+
# Capture script name for usage display
11+
SCRIPT_NAME="$(basename "$0")"
12+
13+
# Usage function
14+
show_usage() {
15+
cat << EOF
16+
Usage: $SCRIPT_NAME [branch] [--force] [--help]
17+
18+
Automated script to update DarwinPrivateFrameworks with RenderBox changes.
19+
20+
Arguments:
21+
branch Target branch to generate from (default: main)
22+
23+
Options:
24+
--force Force push the branch when creating PR
25+
--help Show this help message
26+
27+
Examples:
28+
$SCRIPT_NAME # Update from main branch
29+
$SCRIPT_NAME develop # Update from develop branch
30+
$SCRIPT_NAME main --force # Update from main with force push
31+
$SCRIPT_NAME --help # Show this help
32+
33+
Description:
34+
This script automates the process of updating DarwinPrivateFrameworks
35+
with the latest RenderBox changes by:
36+
1. Setting up a git worktree for the target branch
37+
2. Cloning DarwinPrivateFrameworks repository
38+
3. Generating RB template from OpenRenderBox
39+
4. Updating headers and Swift interface templates
40+
5. Creating and pushing a PR with the changes
41+
EOF
42+
}
43+
44+
# Parse command line arguments
45+
TARGET_BRANCH="main"
46+
FORCE_PUSH=""
47+
48+
# Parse arguments
49+
while [[ $# -gt 0 ]]; do
50+
case $1 in
51+
--help)
52+
show_usage
53+
exit 0
54+
;;
55+
--force)
56+
FORCE_PUSH="--force"
57+
shift
58+
;;
59+
*)
60+
TARGET_BRANCH="$1"
61+
shift
62+
;;
63+
esac
64+
done
65+
66+
SCRIPT_ROOT="$(dirname $(dirname $(filepath $0)))"
67+
ORB_REPO_DIR="$SCRIPT_ROOT/.orb_repo"
68+
OPENRENDERBOX_ROOT="$ORB_REPO_DIR"
69+
RB_REPO_DIR="$SCRIPT_ROOT/.rb_repo"
70+
71+
echo "Starting DarwinPrivateFrameworks bump PR workflow..."
72+
echo "Target branch: $TARGET_BRANCH"
73+
if [[ -n "$FORCE_PUSH" ]]; then
74+
echo "Force push: enabled"
75+
fi
76+
77+
# Cleanup function
78+
cleanup() {
79+
if [[ -d "$RB_REPO_DIR" ]]; then
80+
echo "Cleaning up temporary repository..."
81+
rm -rf "$RB_REPO_DIR"
82+
fi
83+
if [[ -d "$ORB_REPO_DIR" ]]; then
84+
echo "Cleaning up git worktree..."
85+
cd "$SCRIPT_ROOT"
86+
git worktree remove --force "$ORB_REPO_DIR" 2>/dev/null || true
87+
fi
88+
}
89+
90+
# Set trap to cleanup on exit
91+
trap cleanup EXIT
92+
93+
cd "$SCRIPT_ROOT"
94+
95+
# Step 1: Setup git worktree for target branch
96+
echo "Setting up git worktree for branch: $TARGET_BRANCH"
97+
if [[ -d "$ORB_REPO_DIR" ]]; then
98+
git worktree remove --force "$ORB_REPO_DIR" 2>/dev/null || true
99+
fi
100+
101+
git worktree add "$ORB_REPO_DIR" "$TARGET_BRANCH"
102+
103+
# Step 2: Clone DarwinPrivateFrameworks repository
104+
echo "Cloning DarwinPrivateFrameworks repository..."
105+
if [[ -d "$RB_REPO_DIR" ]]; then
106+
rm -rf "$RB_REPO_DIR"
107+
fi
108+
109+
gh repo clone OpenSwiftUIProject/DarwinPrivateFrameworks "$RB_REPO_DIR"
110+
111+
# Step 3: Create new branch based on target branch name
112+
echo "Creating new branch: update-rb-$TARGET_BRANCH"
113+
cd "$RB_REPO_DIR"
114+
git checkout -b "update-rb-$TARGET_BRANCH"
115+
116+
# Step 4: Generate RB template
117+
echo "Generating RB template..."
118+
cd "$OPENRENDERBOX_ROOT"
119+
./Scripts/gen_rb_template.sh
120+
121+
# Step 5: Update DarwinPrivateFrameworks with generated content
122+
echo "Updating DarwinPrivateFrameworks content..."
123+
124+
# Update headers in Sources/Headers
125+
if [[ -d ".rb_template/Headers" ]]; then
126+
echo "Updating headers..."
127+
rm -rf "$RB_REPO_DIR/RB/2024/Sources/Headers"/*
128+
cp -r .rb_template/Headers/* "$RB_REPO_DIR/RB/2024/Sources/Headers/"
129+
fi
130+
131+
# Step 6: Commit changes in DarwinPrivateFrameworks
132+
echo "Committing changes..."
133+
cd "$RB_REPO_DIR"
134+
135+
git add .
136+
if git diff --staged --quiet; then
137+
echo "No changes to commit"
138+
else
139+
git commit -m "feat(rb): Update RenderBox from OpenRenderBox $TARGET_BRANCH
140+
141+
- Updated headers from OpenRenderBox sources
142+
- Generated from OpenRenderBox branch: $TARGET_BRANCH"
143+
fi
144+
145+
# Step 7: Update xcframeworks
146+
echo "Updating xcframeworks..."
147+
swift package update-xcframeworks --allow-writing-to-package-directory
148+
149+
# Commit xcframework updates
150+
git add .
151+
if git diff --staged --quiet; then
152+
echo "No xcframework changes to commit"
153+
else
154+
git commit -m "chore(generated): Update RB framework"
155+
fi
156+
157+
# Step 8: Push branch and create PR
158+
echo "Pushing branch and creating PR..."
159+
git push origin "update-rb-$TARGET_BRANCH" $FORCE_PUSH
160+
161+
# Create PR
162+
PR_TITLE="Update RenderBox from OpenRenderBox $TARGET_BRANCH"
163+
PR_BODY="Automated update of RenderBox framework from OpenRenderBox.
164+
165+
**Changes:**
166+
- Updated headers from OpenRenderBox sources
167+
- Updated xcframework binaries
168+
169+
**Source Branch:** $TARGET_BRANCH
170+
**Generated by:** OpenRenderBox bump script"
171+
172+
gh pr create \
173+
--title "$PR_TITLE" \
174+
--body "$PR_BODY" \
175+
--head "update-rb-$TARGET_BRANCH" \
176+
--base main
177+
178+
echo "✅ PR created successfully!"
179+
echo "Branch: update-rb-$TARGET_BRANCH"

Scripts/gen_rb_template.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/zsh
2+
3+
# A `realpath` alternative using the default C implementation.
4+
filepath() {
5+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
6+
}
7+
8+
gen_interface() {
9+
swift build -c release -Xswiftc -emit-module-interface -Xswiftc -enable-library-evolution -Xswiftc -no-verify-emitted-module-interface -Xswiftc -package-name -Xswiftc OpenRenderBox -Xswiftc -Osize
10+
11+
mkdir -p .rb_template
12+
}
13+
14+
gen_header() {
15+
mkdir -p .rb_template/Headers
16+
17+
cp -r Sources/OpenRenderBox/include/OpenRenderBox/* .rb_template/Headers/
18+
19+
# Rename files from ORBxx to RBxx and OpenRenderBoxxx to RenderBoxxx
20+
find .rb_template/Headers -name "ORB*" -type f | while read file; do
21+
new_name=$(echo "$file" | sed 's/ORB/RB/g')
22+
mv "$file" "$new_name"
23+
done
24+
25+
find .rb_template/Headers -name "OpenRenderBox*" -type f | while read file; do
26+
new_name=$(echo "$file" | sed 's/OpenRenderBox/RenderBox/g')
27+
mv "$file" "$new_name"
28+
done
29+
30+
# Update content in all header files
31+
find .rb_template/Headers -name "*.h" -type f | while read file; do
32+
sed -i '' 's/OpenRenderBox/RenderBox/g' "$file"
33+
sed -i '' 's/OPENRENDERBOX/RENDERBOX/g' "$file"
34+
sed -i '' 's/ORB/RB/g' "$file"
35+
done
36+
37+
echo "Generated template headers successfully"
38+
}
39+
40+
OPENRENDERBOX_ROOT="$(dirname $(dirname $(filepath $0)))"
41+
42+
cd $OPENRENDERBOX_ROOT
43+
44+
gen_interface
45+
gen_header

Sources/OpenRenderBox/Path/ORBPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Kyle on 2025/3/25.
66
//
77

8-
#include "ORBPath.h"
8+
#include <OpenRenderBox/ORBPathStorage.h>
99

1010
void ORBPathRetain(ORBPath path) {
1111
// TODO

Sources/OpenRenderBox/Path/ORBPathStorage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// ORBPathStorage.cpp
33
// OpenRenderBox
44

5-
#include "ORBPathStorage.h"
6-
#include "PathStorage.hpp"
7-
#include "../Util/assert.hpp"
5+
#include <OpenRenderBox/ORBPathStorage.h>
6+
#include <OpenRenderBoxCxx/Path/PathStorage.hpp>
7+
#include <OpenRenderBoxCxx/Util/assert.hpp>
88

99
using namespace ORB;
1010

Sources/OpenRenderBox/Path/PathStorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// PathStorage.cpp
33
// OpenRenderBox
44

5-
#include "PathStorage.hpp"
6-
#include "../Util/assert.hpp"
5+
#include <OpenRenderBoxCxx/Path/PathStorage.hpp>
6+
#include <OpenRenderBoxCxx/Util/assert.hpp>
77

88
namespace ORB {
99
namespace Path {

Sources/OpenRenderBox/UUID/ORBUUID.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// ORBUUID.mm
33
// OpenRenderBox
44

5-
#include "ORBUUID.h"
5+
#include <OpenRenderBox/ORBUUID.h>
66

7-
#if ORB_TARGET_OS_DARWIN
7+
#if ORB_TARGET_OS_DARWIN && __OBJC__
88
ORBUUID ORBUUIDInitFromNSUUID(NSUUID *uuid) {
99
ORBUUID ob_uuid;
1010
[uuid getUUIDBytes:ob_uuid.bytes];

0 commit comments

Comments
 (0)