56 lines
2.1 KiB
Bash
Executable File
56 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Build iOS XCFramework for zhixi-document-runtime
|
|
# UDL bindgen + proc-macro C symbols + inline Swift FFI types
|
|
set -e
|
|
|
|
RUST_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
OUT_DIR="$RUST_DIR/bindings/ios"
|
|
LIB_NAME="libzx_document_ffi.a"
|
|
|
|
rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios
|
|
|
|
echo "==> Building for iOS device (arm64)..."
|
|
cargo build --release --target aarch64-apple-ios -p zx_document_ffi
|
|
|
|
echo "==> Building for iOS simulator (arm64)..."
|
|
cargo build --release --target aarch64-apple-ios-sim -p zx_document_ffi
|
|
|
|
echo "==> Building for iOS simulator (x86_64)..."
|
|
cargo build --release --target x86_64-apple-ios -p zx_document_ffi
|
|
|
|
rm -rf "$OUT_DIR/ZxDocumentRuntime.xcframework"
|
|
mkdir -p "$OUT_DIR/device" "$OUT_DIR/simulator" "$OUT_DIR/generated"
|
|
|
|
cp "target/aarch64-apple-ios/release/$LIB_NAME" "$OUT_DIR/device/"
|
|
cp "target/aarch64-apple-ios-sim/release/$LIB_NAME" "$OUT_DIR/simulator/libzx_document_ffi_arm64.a"
|
|
cp "target/x86_64-apple-ios/release/$LIB_NAME" "$OUT_DIR/simulator/libzx_document_ffi_x86_64.a"
|
|
|
|
echo "==> Creating universal iOS simulator static library..."
|
|
lipo -create \
|
|
"$OUT_DIR/simulator/libzx_document_ffi_arm64.a" \
|
|
"$OUT_DIR/simulator/libzx_document_ffi_x86_64.a" \
|
|
-output "$OUT_DIR/simulator/$LIB_NAME"
|
|
|
|
echo "==> Generating Swift bindings (UDL bindgen)..."
|
|
rm -f "$OUT_DIR/generated/zx_document.swift"
|
|
uniffi-bindgen generate \
|
|
--language swift \
|
|
--out-dir "$OUT_DIR/generated" \
|
|
"$RUST_DIR/crates/zx_document_ffi/src/zx_document.udl"
|
|
|
|
echo "==> Patching Swift file for static linking..."
|
|
python3 "$RUST_DIR/scripts/patch-swift.py" "$OUT_DIR/generated/zx_document.swift"
|
|
|
|
echo "==> Checking C ABI symbols..."
|
|
bash "$RUST_DIR/scripts/check-symbols.sh" "$OUT_DIR/simulator/$LIB_NAME"
|
|
|
|
echo "==> Creating XCFramework..."
|
|
xcodebuild -create-xcframework \
|
|
-library "$OUT_DIR/device/$LIB_NAME" \
|
|
-library "$OUT_DIR/simulator/$LIB_NAME" \
|
|
-output "$OUT_DIR/ZxDocumentRuntime.xcframework"
|
|
|
|
echo "==> Done!"
|
|
echo "XCFramework: $OUT_DIR/ZxDocumentRuntime.xcframework"
|
|
echo "Swift sources: $OUT_DIR/generated/"
|