Skip to content

Commit a33e856

Browse files
committed
Add M1 target support to build.sh
1 parent 250df25 commit a33e856

File tree

6 files changed

+50
-31
lines changed

6 files changed

+50
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ DerivedData/
88
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
99
bdkFFI.xcframework.zip
1010
bdkFFI
11+
libbdkffi.a
1112
bdkFFI.h

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ let package = Package(
2424
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2525
.binaryTarget(
2626
name: "bdkFFI",
27-
url: "https://github.com/notmandatory/bdk-swift/releases/download/0.1.3/bdkFFI.xcframework.zip",
28-
checksum: "c0b1e3ea09376b3f316d7d83575e1cd513fc4ad39ef8cf01120a3a1d7757fb97"),
27+
url: "https://github.com/notmandatory/bdk-swift/releases/download/0.1.7/bdkFFI.xcframework.zip",
28+
checksum: "dc51c5c61b78e06fba45fe7d55978726f6f6bb609c2b369f12f3f2e5c24b9ed5"),
2929
// .binaryTarget(name: "bdkFFI", path: "./bdkFFI.xcframework"),
3030
.target(
3131
name: "BitcoinDevKit",

bdkFFI.xcframework/Info.plist

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,43 @@
66
<array>
77
<dict>
88
<key>LibraryIdentifier</key>
9-
<string>macos-x86_64</string>
9+
<string>macos-arm64_x86_64</string>
1010
<key>LibraryPath</key>
1111
<string>bdkFFI.framework</string>
1212
<key>SupportedArchitectures</key>
1313
<array>
14+
<string>arm64</string>
1415
<string>x86_64</string>
1516
</array>
1617
<key>SupportedPlatform</key>
1718
<string>macos</string>
1819
</dict>
1920
<dict>
2021
<key>LibraryIdentifier</key>
21-
<string>ios-arm64</string>
22+
<string>ios-arm64_x86_64-simulator</string>
2223
<key>LibraryPath</key>
2324
<string>bdkFFI.framework</string>
2425
<key>SupportedArchitectures</key>
2526
<array>
2627
<string>arm64</string>
28+
<string>x86_64</string>
2729
</array>
2830
<key>SupportedPlatform</key>
2931
<string>ios</string>
32+
<key>SupportedPlatformVariant</key>
33+
<string>simulator</string>
3034
</dict>
3135
<dict>
3236
<key>LibraryIdentifier</key>
33-
<string>ios-arm64_x86_64-simulator</string>
37+
<string>ios-arm64</string>
3438
<key>LibraryPath</key>
3539
<string>bdkFFI.framework</string>
3640
<key>SupportedArchitectures</key>
3741
<array>
3842
<string>arm64</string>
39-
<string>x86_64</string>
4043
</array>
4144
<key>SupportedPlatform</key>
4245
<string>ios</string>
43-
<key>SupportedPlatformVariant</key>
44-
<string>simulator</string>
4546
</dict>
4647
</array>
4748
<key>CFBundlePackageType</key>

build.sh

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,64 @@ pushd bdk-ffi
66
echo "Confirm bdk-ffi rust lib builds"
77
cargo build --release
88

9-
## build bdk-ffi rust libs for apple targets
10-
echo "Build bdk-ffi libs for apple targets"
9+
echo "Generate bdk-ffi swift bindings"
10+
uniffi-bindgen generate src/bdk.udl --no-format --out-dir ../Sources/BitcoinDevKit --language swift
1111

12-
TARGET_TRIPLES=("x86_64-apple-darwin" "x86_64-apple-ios" "aarch64-apple-ios")
12+
## build bdk-ffi rust libs for apple targets and add to xcframework
13+
echo "Build bdk-ffi libs for apple targets and add to xcframework"
14+
15+
TARGET_TRIPLES=("x86_64-apple-darwin" "aarch64-apple-darwin" "x86_64-apple-ios" "aarch64-apple-ios")
16+
#XCFRAMEWORK_LIBS=""
1317
for TARGET in ${TARGET_TRIPLES[@]}; do
1418
echo "Build bdk-ffi lib for target $TARGET"
1519
cargo build --release --target $TARGET
20+
#XCFRAMEWORK_LIBS="$XCFRAMEWORK_LIBS -library target/$TARGET/release/libbdkffi.a"
1621
done
17-
18-
echo "Generate bdk-ffi swift bindings"
19-
uniffi-bindgen generate src/bdk.udl --no-format --out-dir ../Sources/BitcoinDevKit --language swift
22+
# special build for M1 ios simulator
23+
cargo +nightly build --release -Z build-std --target aarch64-apple-ios-sim
24+
25+
echo "Create lipo static libs for ios-sim to support M1"
26+
mkdir -p target/lipo-ios-sim/release
27+
lipo target/aarch64-apple-ios-sim/release/libbdkffi.a target/x86_64-apple-ios/release/libbdkffi.a -create -output target/lipo-ios-sim/release/libbdkffi.a
28+
29+
echo "Create lipo static libs for macos to support M1"
30+
mkdir -p target/lipo-macos/release
31+
lipo target/aarch64-apple-darwin/release/libbdkffi.a target/x86_64-apple-darwin/release/libbdkffi.a -create -output target/lipo-macos/release/libbdkffi.a
32+
33+
#echo "Create xcframework with xcodebuild"
34+
#xcodebuild -create-xcframework \
35+
# -library target/lipo-ios-sim/release/libbdkffi.a \
36+
# -library target/lipo-macos/release/libbdkffi.a \
37+
# -library target/aarch64-apple-ios/release/libbdkffi.a \
38+
# -output ../bdkFFI.xcframework
39+
2040
popd
2141

2242
# rename bdk.swift bindings to BitcoinDevKit.swift
2343
mv Sources/BitcoinDevKit/bdk.swift Sources/BitcoinDevKit/BitcoinDevKit.swift
2444

25-
# copy bdkFFI.h to bdkFFI.xcframework platforms
26-
PLATFORMS=("macos-x86_64" "ios-arm64_x86_64-simulator" "ios-arm64")
27-
for PLATFORM in ${PLATFORMS[@]}; do
28-
cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/$PLATFORM/bdkFFI.framework/Headers
45+
XCFRAMEWORK_LIBS=("ios-arm64" "ios-arm64_x86_64-simulator" "macos-arm64_x86_64")
46+
for LIB in ${XCFRAMEWORK_LIBS[@]}; do
47+
# copy possibly updated header file
48+
cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/$LIB/bdkFFI.framework/Headers
2949
done
3050

51+
echo "Copy libbdkffi.a files to bdkFFI.xcframework/bdkFFI"
52+
cp bdk-ffi/target/aarch64-apple-ios/release/libbdkffi.a bdkFFI.xcframework/ios-arm64/bdkFFI.framework/bdkFFI
53+
cp bdk-ffi/target/lipo-ios-sim/release/libbdkffi.a bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/bdkFFI
54+
cp bdk-ffi/target/lipo-macos/release/libbdkffi.a bdkFFI.xcframework/macos-arm64_x86_64/bdkFFI.framework/bdkFFI
55+
3156
# remove unneed .h and .modulemap files
3257
rm Sources/BitcoinDevKit/bdkFFI.h
3358
rm Sources/BitcoinDevkit/bdkFFI.modulemap
3459

35-
# add bdkFFI libs to bdkFFI.xcframework
36-
37-
# macos-x86_64 platform
38-
cp bdk-ffi/target/x86_64-apple-darwin/release/libbdkffi.a bdkFFI.xcframework/macos-x86_64/bdkFFI.framework/bdkFFI
39-
40-
# ios-arm64 platform
41-
cp bdk-ffi/target/aarch64-apple-ios/release/libbdkffi.a bdkFFI.xcframework/ios-arm64/bdkFFI.framework/bdkFFI
42-
43-
# ios-arm64_x86_64-simulator, currently x86_64 only (need to make fat binary to add M1)
44-
cp bdk-ffi/target/x86_64-apple-ios/release/libbdkffi.a bdkFFI.xcframework/ios-arm64_x86_64-simulator/bdkFFI.framework/bdkFFI
45-
4660
# TODO add license info
4761

48-
# remove any existing bdkFFI.xcframework.zip
49-
rm bdkFFI.xcframework.zip
62+
if test -f "bdkFFI.xcframework.zip"; then
63+
echo "Remove old bdkFFI.xcframework.zip"
64+
rm bdkFFI.xcframework.zip
65+
fi
66+
5067

5168
# zip bdkFFI.xcframework directory into a bundle for distribution
5269
zip -9 -r bdkFFI.xcframework.zip bdkFFI.xcframework

0 commit comments

Comments
 (0)