-
Notifications
You must be signed in to change notification settings - Fork 55
/
build-xcframework.sh
executable file
·185 lines (158 loc) · 4.96 KB
/
build-xcframework.sh
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
#!/usr/bin/env sh
set -eo pipefail
# Check if lipo and xcodebuild exist
if [ -z `command -v lipo` ] || [ -z `command -v xcodebuild` ] || [ -z `command -v jq` ]
then
echo "!!! lipo, xcodebuild or jq could not be found !!!"
help
fi
NAME="anoncreds"
VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name == "anoncreds") | .version')
BUNDLE_IDENTIFIER="org.hyperledger.$NAME"
LIBRARY_NAME="lib$NAME.a"
XC_FRAMEWORK_NAME="$NAME.xcframework"
FRAMEWORK_LIBRARY_NAME="`tr '[:lower:]' '[:upper:]' <<< ${NAME:0:1}`${NAME:1}"
FRAMEWORK_NAME="$FRAMEWORK_LIBRARY_NAME.framework"
HEADER_NAME="lib$NAME.h"
OUT_PATH="out"
MIN_IOS_VERSION="12.0"
# Setting some default paths
AARCH64_APPLE_IOS_PATH="./target/aarch64-apple-ios/release"
AARCH64_APPLE_IOS_SIM_PATH="./target/aarch64-apple-ios-sim/release"
X86_64_APPLE_IOS_PATH="./target/x86_64-apple-ios/release"
HEADER_PATH="./include"
# Simple helper command to display some information
Help() {
echo "required dependencies:"
echo " - lipo"
echo " - jq"
echo " - xcodebuild"
echo "To build an xcframework with underlying Frameworks"
echo "the following can be passed in as positional arguments"
echo " 1. Path to the aarch64-apple-ios where the dylib is stored"
echo " 2. Path to the aarch64-apple-ios-sim where the dylib is stored"
echo " 3. Path to the x86_64-apple-ios where the dylib is stored"
echo " 4. Path to the header file, excluding the header"
echo "Make sure to add the 'release' section of the path for a"
echo "release build."
exit
}
# override if its provided
if [ ! -z "$1" ]
then
AARCH64_APPLE_IOS_PATH=$1
fi
# override if its provided
if [ ! -z "$2" ]
then
AARCH64_APPLE_IOS_SIM_PATH=$2
fi
# override if its provided
if [ ! -z "$3" ]
then
X86_64_APPLE_IOS_PATH=$3
fi
# override if its provided
if [ ! -z "$4" ]
then
HEADER_PATH=$4
fi
if [ ! -f $AARCH64_APPLE_IOS_SIM_PATH/$LIBRARY_NAME ]
then
echo "$AARCH64_APPLE_IOS_SIM_PATH/$LIBRARY_NAME does not exist!"
exit
fi
if [ ! -f $AARCH64_APPLE_IOS_PATH/$LIBRARY_NAME ]
then
echo "$AARCH64_APPLE_IOS_PATH/$LIBRARY_NAME does not exist!"
exit
fi
if [ ! -f $X86_64_APPLE_IOS_PATH/$LIBRARY_NAME ]
then
echo "$X86_64_APPLE_IOS_PATH/$LIBRARY_NAME does not exist!"
exit
fi
if [ ! -f $HEADER_PATH/$HEADER_NAME ]
then
echo "$HEADER_PATH/$HEADER_NAME does not exist!"
exit
fi
# Displaying the supplied paths to the user
# So there will not be any mistakes
cat << EOF
Using $AARCH64_APPLE_IOS_PATH for aarch64-apple-ios
Using $AARCH64_APPLE_IOS_SIM_PATH for aarch64-apple-ios-sim
Using $X86_64_APPLE_IOS_PATH for x86_64-apple-ios
Building xcframework with the following values:
Name: $NAME
Version: $VERSION
Bundle identifier: $BUNDLE_IDENTIFIER
Library name: $LIBRARY_NAME
Framework name: $FRAMEWORK_NAME
XCFramework name: $XC_FRAMEWORK_NAME
Framework library name: $FRAMEWORK_LIBRARY_NAME
EOF
echo "Setting op output directory in $OUT_PATH"
mkdir $OUT_PATH
echo "Combining aarch64 and x86-64 for the simulator.."
lipo -create $AARCH64_APPLE_IOS_SIM_PATH/$LIBRARY_NAME \
$X86_64_APPLE_IOS_PATH/$LIBRARY_NAME \
-output $OUT_PATH/sim-$LIBRARY_NAME
echo "Creating a framework template..."
mkdir $OUT_PATH/$FRAMEWORK_NAME
cd $OUT_PATH/$FRAMEWORK_NAME
mkdir Headers
cp ../../$HEADER_PATH/$HEADER_NAME Headers/$FRAMEWORK_LIBRARY_NAME.h
mkdir Modules
touch Modules/module.modulemap
cat <<EOT >> Modules/module.modulemap
framework module $FRAMEWORK_LIBRARY_NAME {
umbrella header "$FRAMEWORK_LIBRARY_NAME.h"
export *
module * { export * }
}
EOT
cat <<EOT >> Info.plist
<?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>CFBundleExecutable</key>
<string>$FRAMEWORK_LIBRARY_NAME</string>
<key>CFBundleIdentifier</key>
<string>$BUNDLE_IDENTIFIER</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$NAME</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$VERSION</string>
<key>NSPrincipalClass</key>
<string></string>
<key>MinimumOSVersion</key>
<string>$MIN_IOS_VERSION</string>
</dict>
</plist>
EOT
cd ..
echo "Creating both frameworks (real device and simulator)..."
mkdir sim
mkdir real
cp -r $FRAMEWORK_NAME sim/
cp -r $FRAMEWORK_NAME real/
mv sim-$LIBRARY_NAME sim/$FRAMEWORK_NAME/$FRAMEWORK_LIBRARY_NAME
cp ../$AARCH64_APPLE_IOS_PATH/$LIBRARY_NAME real/$FRAMEWORK_NAME/$FRAMEWORK_LIBRARY_NAME
echo "Creating XC Framework..."
xcodebuild -create-xcframework \
-framework sim/$FRAMEWORK_NAME \
-framework real/$FRAMEWORK_NAME \
-output $XC_FRAMEWORK_NAME
echo "cleaning up..."
rm -rf $FRAMEWORK_NAME real sim
echo "Framework written to $OUT_PATH/$XC_FRAMEWORK_NAME"