-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathxcframework_utils.sh
More file actions
94 lines (84 loc) · 3.43 KB
/
xcframework_utils.sh
File metadata and controls
94 lines (84 loc) · 3.43 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
archs=("iphoneos.arm64" "iphonesimulator.arm64" "iphonesimulator.x86_64")
dylib_ext=so
create_plist() {
name=$1
identifier=$2
plist_file=$3
cat > $plist_file << PLIST_TEMPLATE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleName</key>
<string>$name</string>
<key>CFBundleExecutable</key>
<string>$name</string>
<key>CFBundleIdentifier</key>
<string>$identifier</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>MinimumOSVersion</key>
<string>13.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
PLIST_TEMPLATE
}
# convert lib-dynloads to xcframeworks
create_xcframework_from_dylibs() {
iphone_dir=$1
simulator_arm64_dir=$2
simulator_x86_64_dir=$3
dylib_relative_path=$4
origin_prefix=$5
out_dir=$6
dylib_tmp_dir=$(mktemp -d)
pushd -- "${dylib_tmp_dir}" >/dev/null
echo "Creating framework for $dylib_relative_path"
dylib_without_ext=$(echo $dylib_relative_path | cut -d "." -f 1)
framework=$(echo $dylib_without_ext | tr "/" ".")
framework_identifier=${framework//_/-}
while [[ $framework_identifier == -* ]]; do
framework_identifier=${framework_identifier#-}
done
framework_identifier=${framework_identifier:-framework}
# creating "iphoneos" framework
fd=iphoneos/$framework.framework
mkdir -p $fd
mv "$iphone_dir/$dylib_relative_path" $fd/$framework
echo "Frameworks/$framework.framework/$framework" > "$iphone_dir/$dylib_without_ext.fwork"
install_name_tool -id @rpath/$framework.framework/$framework $fd/$framework
create_plist $framework "org.python.$framework_identifier" $fd/Info.plist
echo "$origin_prefix/$dylib_without_ext.fwork" > $fd/$framework.origin
# creating "iphonesimulator" framework
fd=iphonesimulator/$framework.framework
mkdir -p $fd
lipo -create \
$(find "$simulator_arm64_dir" -path "$simulator_arm64_dir/$dylib_without_ext.*.$dylib_ext" -o -path "$simulator_arm64_dir/$dylib_without_ext.$dylib_ext") \
$(find "$simulator_x86_64_dir" -path "$simulator_x86_64_dir/$dylib_without_ext.*.$dylib_ext" -o -path "$simulator_x86_64_dir/$dylib_without_ext.$dylib_ext") \
-output $fd/$framework
find "$simulator_arm64_dir" -path "$simulator_arm64_dir/$dylib_without_ext.*.$dylib_ext" -o -path "$simulator_arm64_dir/$dylib_without_ext.$dylib_ext" -delete
find "$simulator_x86_64_dir" -path "$simulator_x86_64_dir/$dylib_without_ext.*.$dylib_ext" -o -path "$simulator_x86_64_dir/$dylib_without_ext.$dylib_ext" -delete
install_name_tool -id @rpath/$framework.framework/$framework $fd/$framework
create_plist $framework "org.python.$framework_identifier" $fd/Info.plist
echo "$origin_prefix/$dylib_without_ext.fwork" > $fd/$framework.origin
# merge frameworks info xcframework
xcodebuild -create-xcframework \
-framework "iphoneos/$framework.framework" \
-framework "iphonesimulator/$framework.framework" \
-output $out_dir/$framework.xcframework
# cleanup
popd >/dev/null
rm -rf "${dylib_tmp_dir}" >/dev/null
}