-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathapple_create_xcframework.sh
More file actions
executable file
·198 lines (178 loc) · 6.15 KB
/
Copy pathapple_create_xcframework.sh
File metadata and controls
executable file
·198 lines (178 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
# =============================================================================
# Apple XCFramework Creation Script for LSL
# =============================================================================
# Creates an XCFramework from macOS, iOS, and iOS Simulator frameworks.
#
# Usage:
# ./scripts/apple_create_xcframework.sh --macos <path> --ios <path> --ios-simulator <path> [--output <dir>]
#
# Environment Variables:
# APPLE_CODE_SIGN_IDENTITY_APP - Code signing identity (default: "Developer ID Application")
# LSL_VERSION - Version string for output filename (optional)
#
# Examples:
# # Create XCFramework from all three platforms
# ./scripts/apple_create_xcframework.sh \
# --macos build-macOS/Frameworks/lsl.framework \
# --ios build-iOS/Frameworks/lsl.framework \
# --ios-simulator build-iOS-Simulator/Frameworks/lsl.framework
#
# # Create XCFramework with custom output directory
# ./scripts/apple_create_xcframework.sh \
# --macos build-macOS/Frameworks/lsl.framework \
# --ios build-iOS/Frameworks/lsl.framework \
# --ios-simulator build-iOS-Simulator/Frameworks/lsl.framework \
# --output package/
# =============================================================================
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Default configuration
SIGN_IDENTITY="${APPLE_CODE_SIGN_IDENTITY_APP:-Developer ID Application}"
OUTPUT_DIR="."
MACOS_FRAMEWORK=""
IOS_FRAMEWORK=""
IOS_SIM_FRAMEWORK=""
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--macos)
MACOS_FRAMEWORK="$2"
shift 2
;;
--ios)
IOS_FRAMEWORK="$2"
shift 2
;;
--ios-simulator)
IOS_SIM_FRAMEWORK="$2"
shift 2
;;
--output)
OUTPUT_DIR="$2"
shift 2
;;
--identity)
SIGN_IDENTITY="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 --macos <path> --ios <path> --ios-simulator <path> [--output <dir>]"
echo ""
echo "Options:"
echo " --macos <path> Path to macOS framework"
echo " --ios <path> Path to iOS device framework"
echo " --ios-simulator <path> Path to iOS simulator framework"
echo " --output <dir> Output directory (default: current directory)"
echo " --identity <name> Override code signing identity"
echo ""
echo "Environment Variables:"
echo " APPLE_CODE_SIGN_IDENTITY_APP - Code signing identity"
echo " LSL_VERSION - Version for output filename"
exit 0
;;
-*)
echo "Unknown option: $1"
exit 1
;;
*)
echo "Unexpected argument: $1"
exit 1
;;
esac
done
# Validate inputs - need at least two frameworks
FRAMEWORK_COUNT=0
FRAMEWORK_ARGS=()
if [[ -n "$MACOS_FRAMEWORK" ]]; then
if [[ ! -d "$MACOS_FRAMEWORK" ]]; then
echo "Error: macOS framework not found at: $MACOS_FRAMEWORK"
exit 1
fi
FRAMEWORK_ARGS+=("-framework" "$MACOS_FRAMEWORK")
((FRAMEWORK_COUNT++))
fi
if [[ -n "$IOS_FRAMEWORK" ]]; then
if [[ ! -d "$IOS_FRAMEWORK" ]]; then
echo "Error: iOS framework not found at: $IOS_FRAMEWORK"
exit 1
fi
FRAMEWORK_ARGS+=("-framework" "$IOS_FRAMEWORK")
((FRAMEWORK_COUNT++))
fi
if [[ -n "$IOS_SIM_FRAMEWORK" ]]; then
if [[ ! -d "$IOS_SIM_FRAMEWORK" ]]; then
echo "Error: iOS Simulator framework not found at: $IOS_SIM_FRAMEWORK"
exit 1
fi
FRAMEWORK_ARGS+=("-framework" "$IOS_SIM_FRAMEWORK")
((FRAMEWORK_COUNT++))
fi
if [[ $FRAMEWORK_COUNT -lt 2 ]]; then
echo "Error: At least two frameworks required to create XCFramework"
echo "Provide --macos, --ios, and/or --ios-simulator paths"
exit 1
fi
# Determine version
if [[ -z "$LSL_VERSION" ]]; then
# Try to get from macOS framework Info.plist
if [[ -n "$MACOS_FRAMEWORK" ]]; then
INFO_PLIST="$MACOS_FRAMEWORK/Versions/A/Resources/Info.plist"
if [[ -f "$INFO_PLIST" ]]; then
LSL_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFO_PLIST" 2>/dev/null || echo "")
fi
fi
# Try iOS framework
if [[ -z "$LSL_VERSION" && -n "$IOS_FRAMEWORK" ]]; then
INFO_PLIST="$IOS_FRAMEWORK/Info.plist"
if [[ -f "$INFO_PLIST" ]]; then
LSL_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFO_PLIST" 2>/dev/null || echo "")
fi
fi
if [[ -z "$LSL_VERSION" ]]; then
LSL_VERSION="unknown"
fi
fi
# Create output directory
mkdir -p "$OUTPUT_DIR"
XCFRAMEWORK_PATH="$OUTPUT_DIR/lsl.xcframework"
ZIP_PATH="$OUTPUT_DIR/lsl.xcframework.${LSL_VERSION}.zip"
echo "=== XCFramework Creation ==="
echo "Version: $LSL_VERSION"
echo "Identity: $SIGN_IDENTITY"
echo "Output: $XCFRAMEWORK_PATH"
echo ""
echo "Input frameworks:"
[[ -n "$MACOS_FRAMEWORK" ]] && echo " macOS: $MACOS_FRAMEWORK"
[[ -n "$IOS_FRAMEWORK" ]] && echo " iOS: $IOS_FRAMEWORK"
[[ -n "$IOS_SIM_FRAMEWORK" ]] && echo " iOS Simulator: $IOS_SIM_FRAMEWORK"
echo ""
# Remove existing XCFramework
rm -rf "$XCFRAMEWORK_PATH"
# Create XCFramework
echo "Creating XCFramework..."
xcodebuild -create-xcframework \
"${FRAMEWORK_ARGS[@]}" \
-output "$XCFRAMEWORK_PATH"
# Sign the XCFramework
echo ""
echo "Signing XCFramework..."
codesign --force --deep --sign "$SIGN_IDENTITY" "$XCFRAMEWORK_PATH"
# Verify signature
echo ""
echo "Verifying XCFramework signature..."
codesign --verify --verbose --deep --strict "$XCFRAMEWORK_PATH"
# Create zip archive
echo ""
echo "Creating zip archive: $ZIP_PATH"
ditto -c -k --sequesterRsrc --keepParent "$XCFRAMEWORK_PATH" "$ZIP_PATH"
echo ""
echo "=== XCFramework Complete ==="
echo "XCFramework: $XCFRAMEWORK_PATH"
echo "Zip archive: $ZIP_PATH"
# Export for use in CI
if [[ -n "$GITHUB_ENV" ]]; then
echo "XCFRAMEWORK_PATH=$XCFRAMEWORK_PATH" >> "$GITHUB_ENV"
echo "XCFRAMEWORK_ZIP=$ZIP_PATH" >> "$GITHUB_ENV"
fi