Simplify build.sh and add template bdkFFI.xcframework to repo

This commit is contained in:
Steve Myers 2021-11-23 22:46:38 -08:00
parent 2ccd89ed2e
commit 71496cd56a
No known key found for this signature in database
GPG Key ID: 8105A46B22C2D051
10 changed files with 120 additions and 2167 deletions

10
.gitignore vendored
View File

@ -6,8 +6,8 @@
xcuserdata/ xcuserdata/
DerivedData/ DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
/*.xcframework bdkFFI.xcframework.zip
!bdkFFI-umbrella.h bdkFFI
!module.modulemap bdkFFI.h
!info.plist bdk.swift
*.xcframework.zip BitcoinDevKit.swift

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
<?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>macos-x86_64</string>
<key>LibraryPath</key>
<string>bdkFFI.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>macos</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>bdkFFI.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>bdkFFI.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>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>

View File

@ -0,0 +1,4 @@
// This is the "umbrella header" for our combined Rust code library.
// It needs to import all of the individual headers.
#import "bdkFFI.h"

View File

@ -0,0 +1,6 @@
framework module bdkFFI {
umbrella header "bdkFFI-umbrella.h"
export *
module * { export * }
}

View File

@ -0,0 +1,4 @@
// This is the "umbrella header" for our combined Rust code library.
// It needs to import all of the individual headers.
#import "bdkFFI.h"

View File

@ -0,0 +1,6 @@
framework module bdkFFI {
umbrella header "bdkFFI-umbrella.h"
export *
module * { export * }
}

View File

@ -0,0 +1,4 @@
// This is the "umbrella header" for our combined Rust code library.
// It needs to import all of the individual headers.
#import "bdkFFI.h"

View File

@ -0,0 +1,6 @@
framework module bdkFFI {
umbrella header "bdkFFI-umbrella.h"
export *
module * { export * }
}

View File

@ -1,75 +1,59 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
BUILD_PROFILE=release ## confirm bdk-ffi rust lib builds
BDKFFI_DIR=bdk-ffi pushd bdk-ffi
TARGET_DIR=$BDKFFI_DIR/target echo "Confirm bdk-ffi rust lib builds"
STATIC_LIB_NAME=libbdkffi.a
SWIFT_DIR="$BDKFFI_DIR/bindings/bdk-swift"
XCFRAMEWORK_NAME="bdkFFI"
XCFRAMEWORK_ROOT="$XCFRAMEWORK_NAME.xcframework"
XCFRAMEWORK_COMMON="$XCFRAMEWORK_ROOT/common/$XCFRAMEWORK_NAME.framework"
## build bdk-ffi rust libs
echo "Build bdk-ffi rust library"
pushd $BDKFFI_DIR
cargo build --release cargo build --release
echo "Generate bdk-ffi swift bindings" ## build bdk-ffi rust libs for apple targets
uniffi-bindgen generate src/bdk.udl --no-format --out-dir bindings/bdk-swift/ --language swift echo "Build bdk-ffi libs for apple targets"
swiftc -module-name bdk -emit-library -o libbdkffi.dylib -emit-module -emit-module-path bindings/bdk-swift/ -parse-as-library -L target/release/ -lbdkffi -Xcc -fmodule-map-file=bindings/bdk-swift/$XCFRAMEWORK_NAME.modulemap bindings/bdk-swift/bdk.swift -suppress-warnings
## build bdk-ffi rust libs into xcframework
echo "Build bdk-ffi libs into swift xcframework"
TARGET_TRIPLES=("x86_64-apple-darwin" "x86_64-apple-ios" "aarch64-apple-ios") TARGET_TRIPLES=("x86_64-apple-darwin" "x86_64-apple-ios" "aarch64-apple-ios")
for TARGET in ${TARGET_TRIPLES[@]}; do for TARGET in ${TARGET_TRIPLES[@]}; do
echo "Build bdk-ffi lib for target $TARGET" echo "Build bdk-ffi lib for target $TARGET"
cargo build --release --target $TARGET cargo build --release --target $TARGET
echo $?
done done
echo "Generate bdk-ffi swift bindings"
uniffi-bindgen generate src/bdk.udl --no-format --out-dir ../Sources/BitcoinDevKit --language swift
popd popd
## Manually construct xcframework # rename bdk.swift bindings to BitcoinDevKit.swift
mv Sources/BitcoinDevKit/bdk.swift Sources/BitcoinDevKit/BitcoinDevKit.swift
# Cleanup prior build # copy bdkFFI.h to bdkFFI.xcframework platforms
rm -rf "$XCFRAMEWORK_ROOT" PLATFORMS=("macos-x86_64" "ios-arm64_x86_64-simulator" "ios-arm64")
rm -f $XCFRAMEWORK_ROOT.zip for PLATFORM in ${PLATFORMS[@]}; do
cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/$PLATFORM/bdkFFI.framework/Headers
done
# Common files # remove unneed .h and .modulemap files
mkdir -p "$XCFRAMEWORK_COMMON/Modules" rm Sources/BitcoinDevKit/bdkFFI.h
cp "$SWIFT_DIR/module.modulemap" "$XCFRAMEWORK_COMMON/Modules/" rm Sources/BitcoinDevkit/bdkFFI.modulemap
mkdir -p "$XCFRAMEWORK_COMMON/Headers"
cp "$SWIFT_DIR/$XCFRAMEWORK_NAME-umbrella.h" "$XCFRAMEWORK_COMMON/Headers"
cp "$SWIFT_DIR/$XCFRAMEWORK_NAME.h" "$XCFRAMEWORK_COMMON/Headers"
# macOS x86_64 hardware # add bdkFFI libs to bdkFFI.xcframework
mkdir -p "$XCFRAMEWORK_ROOT/macos-x86_64"
cp -R "$XCFRAMEWORK_COMMON" "$XCFRAMEWORK_ROOT/macos-x86_64/$XCFRAMEWORK_NAME.framework"
cp "$TARGET_DIR/x86_64-apple-darwin/$BUILD_PROFILE/$STATIC_LIB_NAME" "$XCFRAMEWORK_ROOT/macos-x86_64/$XCFRAMEWORK_NAME.framework/$XCFRAMEWORK_NAME"
# iOS hardware # macos-x86_64 platform
mkdir -p "$XCFRAMEWORK_ROOT/ios-arm64" cp bdk-ffi/target/x86_64-apple-darwin/release/libbdkffi.a bdkFFI.xcframework/macos-x86_64/bdkFFI.framework/bdkFFI
cp -R "$XCFRAMEWORK_COMMON" "$XCFRAMEWORK_ROOT/ios-arm64/$XCFRAMEWORK_NAME.framework"
cp "$TARGET_DIR/aarch64-apple-ios/$BUILD_PROFILE/$STATIC_LIB_NAME" "$XCFRAMEWORK_ROOT/ios-arm64/$XCFRAMEWORK_NAME.framework/$XCFRAMEWORK_NAME"
# iOS simulator, currently x86_64 only (need to make fat binary to add M1) # ios-arm64 platform
mkdir -p "$XCFRAMEWORK_ROOT/ios-arm64_x86_64-simulator" cp bdk-ffi/target/aarch64-apple-ios/release/libbdkffi.a bdkFFI.xcframework/ios-arm64/bdkFFI.framework/bdkFFI
cp -R "$XCFRAMEWORK_COMMON" "$XCFRAMEWORK_ROOT/ios-arm64_x86_64-simulator/$XCFRAMEWORK_NAME.framework"
cp "$TARGET_DIR/x86_64-apple-ios/$BUILD_PROFILE/$STATIC_LIB_NAME" "$XCFRAMEWORK_ROOT/ios-arm64_x86_64-simulator/$XCFRAMEWORK_NAME.framework/$XCFRAMEWORK_NAME" # ios-arm64_x86_64-simulator, currently x86_64 only (need to make fat binary to add M1)
cp bdk-ffi/target/x86_64-apple-ios/release/libbdkffi.a bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/bdkFFI
# Set up the metadata for the XCFramework as a whole.
cp "$SWIFT_DIR/Info.plist" "$XCFRAMEWORK_ROOT/Info.plist"
# TODO add license info # TODO add license info
# Remove common # remove any existing bdkFFI.xcframework.zip
rm -rf "$XCFRAMEWORK_ROOT/common" rm bdkFFI.xcframework.zip
# Zip it all up into a bundle for distribution. # zip bdkFFI.xcframework directory into a bundle for distribution
zip -9 -r "$XCFRAMEWORK_ROOT.zip" "$XCFRAMEWORK_ROOT" zip -9 -r bdkFFI.xcframework.zip bdkFFI.xcframework
# compute bdkFFI.xcframework.zip checksum
echo checksum:
swift package compute-checksum bdkFFI.xcframework.zip swift package compute-checksum bdkFFI.xcframework.zip
# Cleanup build ? # TODO update Package.swift with checksum
# rm -rf "$XCFRAMEWORK_ROOT" # TODO upload zip to github release