Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ android/src/main/jniLibs/

/macos/frostdart.xcframework/
/ios/libfrostdart.a
/ios/frostdart.xcframework/
20 changes: 15 additions & 5 deletions ios/frostdart.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ Bitcoin wallets.
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'

# libfrostdart.a is produced by scripts/ios/download.sh (release artifact)
# or scripts/ios/build_all.sh (build from source). Both drop it next to this
# podspec. Consumers must run one of those before `pod install`.
s.vendored_libraries = 'libfrostdart.a'
# frostdart.xcframework is produced by scripts/ios/build_all.sh (build from
# source) or scripts/ios/download.sh (release artifact). Both drop it next
# to this podspec. Consumers must run one of those before `pod install`.
# The XCFramework carries arm64 device and arm64 simulator slices; a plain
# static library cannot hold both.
s.vendored_frameworks = 'frostdart.xcframework'

s.dependency 'Flutter'
s.platform = :ios, '15.0'
Expand All @@ -34,7 +36,15 @@ Bitcoin wallets.
'DEFINES_MODULE' => 'YES',
# Flutter.framework does not contain a i386 slice.
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386',
'OTHER_LDFLAGS' => '-force_load ${PODS_TARGET_SRCROOT}/libfrostdart.a',
}
# The Dart side resolves symbols from the process at runtime
# (DynamicLibrary.process()), so the whole archive must be linked into the
# app binary. This must live in user_target_xcconfig (not
# pod_target_xcconfig): CocoaPods only extracts the matching
# device/simulator XCFramework slice into PODS_XCFRAMEWORKS_BUILD_DIR
# while building the user target, after the pod target is built.
s.user_target_xcconfig = {
'OTHER_LDFLAGS' => '-force_load ${PODS_XCFRAMEWORKS_BUILD_DIR}/frostdart/libfrostdart.a',
}
s.swift_version = '5.0'
end
31 changes: 25 additions & 6 deletions scripts/ios/build_all.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
#!/bin/bash
set -e

LIB_ROOT=../..
# Absolute path to the frostdart repo root (this script lives in scripts/ios).
FROSTDART_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"

cd "$LIB_ROOT/src/serai/hrf" || exit
cd "$FROSTDART_ROOT/src/serai/hrf" || exit

# cargokit's artifact search uses the Cargo package name verbatim, but cargo
# normalizes dashes to underscores in the emitted filename. Rename so cargo's
# output ("libfrostdart.a") and the podspec's vendored_libraries entry agree.
# output ("libfrostdart.a") and the podspec's vendored_frameworks entry agree.
# BSD sed (macOS) syntax; idempotent.
sed -i '' 's/^name = "hrf-api"$/name = "frostdart"/' Cargo.toml

# Build for both iOS device (aarch64-apple-ios) and the iOS Simulator on
# Apple Silicon (aarch64-apple-ios-sim). Both slices are arm64, so they
# cannot be combined with lipo; they are packaged as an XCFramework instead.
export IPHONEOS_DEPLOYMENT_TARGET=15.0
export RUSTFLAGS="-C link-arg=-mios-version-min=15.0"
export CARGO_TARGET_AARCH64_APPLE_IOS_RUSTFLAGS="-C link-arg=-mios-version-min=15.0"
export CARGO_TARGET_AARCH64_APPLE_IOS_SIM_RUSTFLAGS="-C link-arg=-mios-simulator-version-min=15.0"

cargo build --target aarch64-apple-ios --release --lib
cargo build --target aarch64-apple-ios-sim --release --lib

DEVICE_LIB="../target/aarch64-apple-ios/release/libfrostdart.a"
SIM_LIB="../target/aarch64-apple-ios-sim/release/libfrostdart.a"
HEADERS_DIR="$FROSTDART_ROOT/src/serai/hrf"

# Keep the legacy device-only static library next to the podspec for any
# consumers that still reference it directly.
cp "$DEVICE_LIB" "$FROSTDART_ROOT/ios/libfrostdart.a"

cp ../target/aarch64-apple-ios/release/libfrostdart.a \
"$LIB_ROOT/../ios/libfrostdart.a"
# Package device + simulator slices as an XCFramework.
rm -rf "$FROSTDART_ROOT/ios/frostdart.xcframework"
xcodebuild -create-xcframework \
-library "$DEVICE_LIB" -headers "$HEADERS_DIR" \
-library "$SIM_LIB" -headers "$HEADERS_DIR" \
-output "$FROSTDART_ROOT/ios/frostdart.xcframework"
10 changes: 10 additions & 0 deletions scripts/ios/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ download_and_verify() {
download_and_verify "frostdart-ios-aarch64.a"

cp "$TMPDIR/frostdart-ios-aarch64.a" "$LIB_ROOT/ios/libfrostdart.a"

# Release artifacts are device-only; wrap the device slice in an XCFramework
# so the podspec's vendored_frameworks entry resolves. Simulator consumers
# must build from source with scripts/ios/build_all.sh instead.
FROSTDART_ROOT="$(cd "$LIB_ROOT" && pwd)"
rm -rf "$FROSTDART_ROOT/ios/frostdart.xcframework"
xcodebuild -create-xcframework \
-library "$FROSTDART_ROOT/ios/libfrostdart.a" \
-headers "$FROSTDART_ROOT/src/serai/hrf" \
-output "$FROSTDART_ROOT/ios/frostdart.xcframework"