-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·321 lines (272 loc) · 9.64 KB
/
build.sh
File metadata and controls
executable file
·321 lines (272 loc) · 9.64 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/bin/bash
set -e
echo "Building Supabase C++ Library for Android and iOS with OpenSSL..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Build both platforms by default
BUILD_ANDROID=true
BUILD_IOS=true
# Check if on macOS for iOS builds
if [[ "$OSTYPE" != "darwin"* ]]; then
print_warning "Not running on macOS, iOS build will be skipped"
BUILD_IOS=false
fi
# Build OpenSSL for both platforms
print_status "===== Building OpenSSL ====="
if [ "$BUILD_ANDROID" = true ] && [ -f "build_openssl_android.sh" ]; then
print_status "Building OpenSSL for Android..."
chmod +x build_openssl_android.sh
./build_openssl_android.sh || {
print_error "Failed to build OpenSSL for Android"
exit 1
}
fi
if [ "$BUILD_IOS" = true ] && [ -f "build_openssl_ios.sh" ]; then
print_status "Building OpenSSL for iOS..."
chmod +x build_openssl_ios.sh
./build_openssl_ios.sh || {
print_error "Failed to build OpenSSL for iOS"
exit 1
}
fi
#
# ANDROID BUILD
#
if [ "$BUILD_ANDROID" = true ]; then
print_status "===== Building for Android ====="
# Clean previous Android builds
print_status "Cleaning previous Android builds..."
rm -rf build-android-* lib/libsupabase_*.so
# Check for Android NDK
if [ -z "$ANDROID_NDK" ]; then
if [ -d "$HOME/Library/Android/sdk/ndk" ]; then
ANDROID_NDK=$(find "$HOME/Library/Android/sdk/ndk" -maxdepth 1 -type d | grep -E '[0-9]' | sort -V | tail -1)
print_status "Found Android NDK at: $ANDROID_NDK"
else
print_error "Android NDK not found!"
print_status "Please set ANDROID_NDK environment variable or install Android NDK"
print_status "Example: export ANDROID_NDK=/path/to/android-ndk"
exit 1
fi
fi
print_status "Using Android NDK: $ANDROID_NDK"
# Check if OpenSSL is available
OPENSSL_BASE="$(pwd)/third_party/openssl-android"
if [ -d "$OPENSSL_BASE" ]; then
print_success "Found OpenSSL Android libraries"
USE_OPENSSL_ANDROID=true
else
print_warning "OpenSSL not found. Building without SSL support."
print_status "To enable SSL support, run: ./build.sh android --with-openssl"
USE_OPENSSL_ANDROID=false
fi
# Create lib directory
mkdir -p lib
# Android ABIs to build for
ANDROID_ABIS=("arm64-v8a" "x86_64")
for ABI in "${ANDROID_ABIS[@]}"; do
print_status "Building for Android $ABI..."
BUILD_DIR="build-android-$ABI"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI="$ABI" \
-DANDROID_PLATFORM=android-21 \
-DANDROID_STL=c++_static \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_VERBOSE_MAKEFILE=ON \
.. || {
print_error "Failed to configure Android build for $ABI"
cd ..
continue
}
make || {
print_error "Failed to build for Android $ABI"
cd ..
continue
}
# Copy the built library
if [ -f "libsupabase.so" ]; then
cp libsupabase.so "../lib/libsupabase_$ABI.so"
print_success "Built Android library for $ABI"
print_status "Library info for $ABI:"
file "../lib/libsupabase_$ABI.so"
if [ "$USE_OPENSSL_ANDROID" = true ] && [ -f "$OPENSSL_BASE/$ABI/lib/libssl.a" ]; then
print_success "SSL support enabled for $ABI"
else
print_warning "No SSL support for $ABI"
fi
fi
cd ..
done
# Clean up build directories
print_status "Cleaning up Android build directories..."
rm -rf build-android-*
print_success "Android build completed!"
print_status "Libraries available in: lib/"
ls -lh lib/
fi
#
# iOS BUILD
#
if [ "$BUILD_IOS" = true ]; then
print_status "===== Building for iOS ====="
# Check for Xcode
if ! command -v xcodebuild &> /dev/null; then
print_error "Xcode not found, iOS build not possible"
exit 1
fi
# Check for OpenSSL iOS libraries
print_status "Checking for OpenSSL iOS libraries..."
if [ ! -d "third_party/openssl-ios/iphoneos/lib" ] || [ ! -f "third_party/openssl-ios/iphoneos/lib/libssl.a" ] ||
[ ! -d "third_party/openssl-ios/iphonesimulator/lib" ] || [ ! -f "third_party/openssl-ios/iphonesimulator/lib/libssl.a" ]; then
print_warning "OpenSSL iOS libraries not found."
print_status "To enable SSL support, run: ./build.sh ios --with-openssl"
USE_SSL_IOS=false
else
print_success "OpenSSL iOS libraries found"
USE_SSL_IOS=true
fi
# Clean previous iOS build
print_status "Cleaning previous iOS build..."
rm -rf build-ios-* ios/
# Create iOS XCFramework directory structure
print_status "Setting up XCFramework structure..."
mkdir -p ios/supabase.xcframework/ios-arm64_x86_64-simulator
mkdir -p ios/supabase.xcframework/ios-arm64
# Function to copy headers
copy_headers() {
local framework_path="$1"
mkdir -p "$framework_path/Headers"
cp include/*.h "$framework_path/Headers/" 2>/dev/null || true
}
# Function to build framework
build_framework() {
local system_name="$1"
local architectures="$2"
local sysroot="$3"
local output_path="$4"
local build_dir="$5"
print_status "Building framework for $system_name with architectures: $architectures"
mkdir -p "$build_dir"
cd "$build_dir"
# Configure CMake
local CMAKE_ARGS=(
-G Xcode
-DCMAKE_SYSTEM_NAME="$system_name"
-DCMAKE_OSX_ARCHITECTURES="$architectures"
-DCMAKE_OSX_SYSROOT="$sysroot"
-DCMAKE_OSX_DEPLOYMENT_TARGET=12.0
-DCMAKE_INSTALL_PREFIX="$(pwd)/install"
-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO
-DCMAKE_IOS_INSTALL_COMBINED=YES
)
if [ "$USE_SSL_IOS" = true ]; then
CMAKE_ARGS+=(-DUSE_SSL=ON)
fi
cmake .. "${CMAKE_ARGS[@]}" || {
print_error "Failed to configure $system_name build"
cd ..
exit 1
}
# Build
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) || {
print_error "Failed to build $system_name framework"
cd ..
exit 1
}
# Setup framework destination
local dest_dir="../ios/supabase.xcframework/$output_path"
local framework_src="Release-$sysroot/supabase.framework"
local framework_dest="$dest_dir/supabase.framework"
if [ -d "$framework_src" ]; then
mkdir -p "$dest_dir"
cp -R "$framework_src" "$framework_dest"
copy_headers "$framework_dest"
print_success "Built framework for $output_path"
else
print_error "Expected framework not found at $framework_src"
cd ..
exit 1
fi
cd ..
rm -rf "$build_dir"
}
# Build iOS frameworks
print_status "Building iOS frameworks..."
build_framework "iOS" "arm64;x86_64" "iphonesimulator" "ios-arm64_x86_64-simulator" "build-ios-simulator"
build_framework "iOS" "arm64" "iphoneos" "ios-arm64" "build-ios-device"
# Create XCFramework Info.plist
print_status "Creating XCFramework Info.plist..."
cat > ios/supabase.xcframework/Info.plist << 'EOF'
<?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>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>supabase.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>supabase.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
EOF
print_success "Created XCFramework: ios/supabase.xcframework"
print_status "XCFramework location: $(pwd)/ios/supabase.xcframework"
fi
print_success "===== Build completed successfully! ====="
echo ""
if [ "$BUILD_ANDROID" = true ]; then
print_status "Android libraries (.so):"
ls -lh lib/ 2>/dev/null || print_warning "No Android libraries found in lib/"
echo ""
fi
if [ "$BUILD_IOS" = true ]; then
print_status "iOS framework (.xcframework): ios/supabase.xcframework"
ls -lh ios/ 2>/dev/null || print_warning "No iOS framework found in ios/"
fi