-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework Swift Package script Signed-off-by: Yuki Kishimoto <[email protected]>
- Loading branch information
Showing
2 changed files
with
67 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Inspired by https://github.com/bitcoindevkit/bdk-ffi/blob/014504ee8b6c12234592b68628ab0be888099d45/bdk-swift/build-xcframework.sh | ||
|
||
set -exuo pipefail | ||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
TARGET_DIR="${SCRIPT_DIR}/../../../target" | ||
TEMP_FFI_DIR="${SCRIPT_DIR}/../ffi/swift" | ||
CDY_LIB="libnostr_sdk_ffi.dylib" | ||
STATIC_LIB="libnostr_sdk_ffi.a" | ||
|
||
# Install and targets | ||
rustup target add aarch64-apple-ios # iOS arm64 | ||
rustup target add x86_64-apple-ios # iOS x86_64 | ||
rustup target add aarch64-apple-ios-sim # simulator mac M1 | ||
rustup target add aarch64-apple-darwin # mac M1 | ||
rustup target add x86_64-apple-darwin # mac x86_64 | ||
|
||
# Build for apple targets | ||
cargo build -p nostr-sdk-ffi --release --target x86_64-apple-darwin | ||
cargo build -p nostr-sdk-ffi --release --target aarch64-apple-darwin | ||
cargo build -p nostr-sdk-ffi --release --target x86_64-apple-ios | ||
cargo build -p nostr-sdk-ffi --release --target aarch64-apple-ios | ||
cargo build -p nostr-sdk-ffi --release --target aarch64-apple-ios-sim | ||
|
||
# Make Sources dir | ||
mkdir -p Sources/NostrSDK | ||
|
||
# build bdk-ffi Swift bindings and put in bdk-swift Sources | ||
cargo run -p uniffi-bindgen generate --library "${TARGET_DIR}/aarch64-apple-ios/release/${CDY_LIB}" --no-format --language swift --out-dir Sources/NostrSDK | ||
|
||
# Make universal dirs | ||
mkdir -p "${TARGET_DIR}/darwin-universal/release" # macOS | ||
mkdir -p "${TARGET_DIR}/ios-universal/release" # iOS | ||
mkdir -p "${TARGET_DIR}/ios-universal-sim/release" # iOS Simulator | ||
|
||
# Combine static libs for aarch64 and x86_64 targets via lipo | ||
lipo -create -output "${TARGET_DIR}/darwin-universal/release/${STATIC_LIB}" \ | ||
"${TARGET_DIR}/aarch64-apple-darwin/release/${STATIC_LIB}" \ | ||
"${TARGET_DIR}/x86_64-apple-darwin/release/${STATIC_LIB}" | ||
lipo -create -output "${TARGET_DIR}/ios-universal/release/${STATIC_LIB}" \ | ||
"${TARGET_DIR}/aarch64-apple-ios/release/${STATIC_LIB}" \ | ||
"${TARGET_DIR}/x86_64-apple-ios/release/${STATIC_LIB}" | ||
lipo -create -output "${TARGET_DIR}/ios-universal-sim/release/${STATIC_LIB}" \ | ||
"${TARGET_DIR}/aarch64-apple-ios-sim/release/${STATIC_LIB}" \ | ||
"${TARGET_DIR}/x86_64-apple-ios/release/${STATIC_LIB}" | ||
|
||
# Move static lib header files to temporary directory | ||
mkdir -p "${TEMP_FFI_DIR}" | ||
mv "Sources/NostrSDK/nostr_sdkFFI.h" "${TEMP_FFI_DIR}/nostr_sdkFFI.h" | ||
mv "Sources/NostrSDK/nostr_sdkFFI.modulemap" "${TEMP_FFI_DIR}/module.modulemap" | ||
|
||
# Remove old xcframework dir | ||
rm -rf "nostr_sdkFFI.xcframework" | ||
|
||
# Create new xcframework directory from static libs and headers | ||
xcodebuild -create-xcframework \ | ||
-library "${TARGET_DIR}/darwin-universal/release/${STATIC_LIB}" \ | ||
-headers "${TEMP_FFI_DIR}" \ | ||
-library "${TARGET_DIR}/ios-universal/release/${STATIC_LIB}" \ | ||
-headers "${TEMP_FFI_DIR}" \ | ||
-library "${TARGET_DIR}/ios-universal-sim/release/${STATIC_LIB}" \ | ||
-headers "${TEMP_FFI_DIR}" \ | ||
-output "nostr_sdkFFI.xcframework" |