-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_ios.sh
executable file
·96 lines (77 loc) · 3.08 KB
/
build_ios.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
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
echo "Starting iOS build process..."
# Remove previous builds and ensure clean state
echo "Cleaning previous builds..."
rm -rf bindings/ios/*
rm -rf ios/
# Create necessary directories
echo "Creating build directories..."
mkdir -p bindings/ios/
# Set iOS deployment target
export IPHONEOS_DEPLOYMENT_TARGET=13.4
# Cargo Build
echo "Building Rust libraries..."
cargo build
# Modify Cargo.toml
echo "Updating Cargo.toml..."
sed -i '' 's/crate_type = .*/crate_type = ["cdylib", "staticlib"]/' Cargo.toml
# Build release
echo "Building release version..."
cargo build --release
# Add iOS targets
echo "Adding iOS targets..."
rustup target add aarch64-apple-ios-sim aarch64-apple-ios
# Build for iOS simulator and device
echo "Building for iOS targets..."
cargo build --release --target=aarch64-apple-ios-sim
cargo build --release --target=aarch64-apple-ios
# Generate Swift bindings
echo "Generating Swift bindings..."
# First, ensure any existing generated files are removed
rm -rf ./bindings/ios/pubkyapp.swift
rm -rf ./bindings/ios/pubkyappFFI.h
rm -rf ./bindings/ios/pubkyappFFI.modulemap
rm -rf ./bindings/ios/Headers
rm -rf ./bindings/ios/ios-arm64
rm -rf ./bindings/ios/ios-arm64-sim
cargo run --bin uniffi-bindgen generate \
--library ./target/release/libpubkyapp.dylib \
--language swift \
--out-dir ./bindings/ios \
|| { echo "Failed to generate Swift bindings"; exit 1; }
# Handle modulemap file
echo "Handling modulemap file..."
if [ -f bindings/ios/pubkyappFFI.modulemap ]; then
mv bindings/ios/pubkyappFFI.modulemap bindings/ios/module.modulemap
else
echo "Warning: modulemap file not found"
fi
# Clean up any existing XCFramework and temporary directories
echo "Cleaning up existing XCFramework..."
rm -rf "bindings/ios/PubkyApp.xcframework"
rm -rf "bindings/ios/Headers"
rm -rf "bindings/ios/ios-arm64"
rm -rf "bindings/ios/ios-arm64-sim"
# Create temporary directories for each architecture
echo "Creating architecture-specific directories..."
mkdir -p "bindings/ios/ios-arm64/Headers"
mkdir -p "bindings/ios/ios-arm64-sim/Headers"
# Copy headers to architecture-specific directories
echo "Copying headers to architecture directories..."
cp bindings/ios/pubkyappFFI.h "bindings/ios/ios-arm64/Headers/"
cp bindings/ios/module.modulemap "bindings/ios/ios-arm64/Headers/"
cp bindings/ios/pubkyappFFI.h "bindings/ios/ios-arm64-sim/Headers/"
cp bindings/ios/module.modulemap "bindings/ios/ios-arm64-sim/Headers/"
# Create XCFramework
echo "Creating XCFramework..."
xcodebuild -create-xcframework \
-library ./target/aarch64-apple-ios-sim/release/libpubkyapp.a -headers "bindings/ios/ios-arm64-sim/Headers" \
-library ./target/aarch64-apple-ios/release/libpubkyapp.a -headers "bindings/ios/ios-arm64/Headers" \
-output "bindings/ios/PubkyApp.xcframework" \
|| { echo "Failed to create XCFramework"; exit 1; }
# Clean up temporary directories
echo "Cleaning up temporary directories..."
rm -rf "bindings/ios/ios-arm64"
rm -rf "bindings/ios/ios-arm64-sim"
echo "iOS build process completed successfully!"