-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_xcframework.sh
More file actions
executable file
·69 lines (52 loc) · 1.97 KB
/
Copy pathbuild_xcframework.sh
File metadata and controls
executable file
·69 lines (52 loc) · 1.97 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
#!/bin/bash
set -e
# Library name
LIB_NAME="rust_swift"
FFI_MODULE="${LIB_NAME}FFI"
SWIFT_SOURCE_NAME="RustSwift"
# Code signing identity — set to empty string to skip signing.
# Example: "Apple Development: Nguyen Van A (XXXXXXXXXX)"
# You can also override at runtime: SIGNING_IDENTITY="..." ./build_xcframework.sh
SIGNING_IDENTITY="${SIGNING_IDENTITY:-""}"
# Target definitions
TARGETS=(
"aarch64-apple-ios"
"aarch64-apple-ios-sim"
"aarch64-apple-darwin"
)
# Adding targets
rustup target add "${TARGETS[@]}"
# Building Rust libraries for each target
for TARGET in "${TARGETS[@]}"; do
cargo build --target "$TARGET" --release
done
OUT_DIR="build/swift"
mkdir -p "$OUT_DIR/Headers"
FIRST_TARGET="${TARGETS[0]}"
LIB_PATH="target/$FIRST_TARGET/release/lib${LIB_NAME}.a"
# Generate Swift source files
cargo run --bin uniffi-bindgen-swift -- "$LIB_PATH" "$OUT_DIR" --swift-sources
# Generate headers
cargo run --bin uniffi-bindgen-swift -- "$LIB_PATH" "$OUT_DIR/Headers" --headers
# Generate modulemap
cargo run --bin uniffi-bindgen-swift -- "$LIB_PATH" "$OUT_DIR/Headers" --modulemap --module-name "$FFI_MODULE" --modulemap-filename module.modulemap
# Create XCFramework
rm -rf "build/${FFI_MODULE}.xcframework"
rm -rf "build/${SWIFT_SOURCE_NAME}.swift"
XCFRAMEWORK_ARGS=()
for TARGET in "${TARGETS[@]}"; do
XCFRAMEWORK_ARGS+=(-library "target/$TARGET/release/lib${LIB_NAME}.a" -headers "$OUT_DIR/Headers")
done
xcodebuild -create-xcframework \
"${XCFRAMEWORK_ARGS[@]}" \
-output "build/${FFI_MODULE}.xcframework"
cp "$OUT_DIR"/*.swift "build/${SWIFT_SOURCE_NAME}.swift"
rm -rf build/swift
# Sign XCFramework
if [ -n "$SIGNING_IDENTITY" ]; then
echo "Signing XCFramework with identity: $SIGNING_IDENTITY"
codesign --timestamp -s "$SIGNING_IDENTITY" "build/${FFI_MODULE}.xcframework"
else
echo "No SIGNING_IDENTITY set, skipping code signing."
fi
echo "Done! XCFramework generated at build/${FFI_MODULE}.xcframework and bindings at build/${SWIFT_SOURCE_NAME}.swift"