Skip to content

Commit 929f992

Browse files
committed
feat: compile framework for mac catalyst
1 parent 4ca8d61 commit 929f992

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

bindings/apple/build_crypto_xcframework.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TARGET_DIR="${SRC_ROOT}/target"
1010

1111
GENERATED_DIR="${SRC_ROOT}/generated"
1212
if [ -d "${GENERATED_DIR}" ]; then rm -rf "${GENERATED_DIR}"; fi
13-
mkdir -p ${GENERATED_DIR}/{macos,simulator}
13+
mkdir -p ${GENERATED_DIR}/{macos,simulator,catalyst}
1414

1515
REL_FLAG="--release"
1616
REL_TYPE_DIR="release"
@@ -19,23 +19,38 @@ TARGET_CRATE=matrix-sdk-crypto-ffi
1919

2020
# Build static libs for all the different architectures
2121

22-
# Required by olm-sys crate
22+
# Required by olm-sys crate. @todo: Is this the right SDK path for Catalyst as well?
2323
export IOS_SDK_PATH=`xcrun --show-sdk-path --sdk iphoneos`
2424

2525
# iOS
26-
echo -e "Building for iOS [1/5]"
26+
echo -e "Building for iOS [1/7]"
2727
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios"
2828

29+
# Mac Catalyst
30+
# 1) The target has no pre=built rust-std, so we use `-Z build-std`.
31+
# how to build-std: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std
32+
# list of targets with prebuilt rust-std: https://doc.rust-lang.org/nightly/rustc/platform-support.html
33+
# 2) requires a recent nightly wih https://github.com/rust-lang/rust/pull/111384 merged
34+
CATALYST_RUST_NIGHTLY="nightly"
35+
echo -e "\nInstalling nightly and rust-src for Mac Catalyst"
36+
rustup toolchain install ${CATALYST_RUST_NIGHTLY} --no-self-update
37+
rustup component add rust-src --toolchain ${CATALYST_RUST_NIGHTLY}
38+
39+
echo -e "\nBuilding for macOS Catalyst (Apple Silicon) [2/7]"
40+
cargo +${CATALYST_RUST_NIGHTLY} build -p ${TARGET_CRATE} ${REL_FLAG} -Z build-std --target aarch64-apple-ios-macabi
41+
echo -e "\nBuilding for macOS Catalyst (Intel) [3/7]"
42+
cargo +${CATALYST_RUST_NIGHTLY} build -p ${TARGET_CRATE} ${REL_FLAG} -Z build-std --target x86_64-apple-ios-macabi
43+
2944
# MacOS
30-
echo -e "\nBuilding for macOS (Apple Silicon) [2/5]"
45+
echo -e "\nBuilding for macOS (Apple Silicon) [4/7]"
3146
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-darwin"
32-
echo -e "\nBuilding for macOS (Intel) [3/5]"
47+
echo -e "\nBuilding for macOS (Intel) [5/7]"
3348
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-darwin"
3449

3550
# iOS Simulator
36-
echo -e "\nBuilding for iOS Simulator (Apple Silicon) [4/5]"
51+
echo -e "\nBuilding for iOS Simulator (Apple Silicon) [6/7]"
3752
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios-sim"
38-
echo -e "\nBuilding for iOS Simulator (Intel) [5/5]"
53+
echo -e "\nBuilding for iOS Simulator (Intel) [7/7]"
3954
cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-ios"
4055

4156
echo -e "\nCreating XCFramework"
@@ -47,6 +62,12 @@ lipo -create \
4762
"${TARGET_DIR}/aarch64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
4863
-output "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a"
4964

65+
# Catalyst
66+
lipo -create \
67+
"${TARGET_DIR}/aarch64-apple-ios-macabi/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
68+
"${TARGET_DIR}/x86_64-apple-ios-macabi/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
69+
-output "${GENERATED_DIR}/catalyst/libmatrix_sdk_crypto_ffi.a"
70+
5071
# iOS Simulator
5172
lipo -create \
5273
"${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
@@ -85,10 +106,13 @@ xcodebuild -create-xcframework \
85106
-headers ${HEADERS_DIR} \
86107
-library "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" \
87108
-headers ${HEADERS_DIR} \
109+
-library "${GENERATED_DIR}/catalyst/libmatrix_sdk_crypto_ffi.a" \
110+
-headers ${HEADERS_DIR} \
88111
-output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework"
89112

90113
# Cleanup
91114
if [ -d "${GENERATED_DIR}/macos" ]; then rm -rf "${GENERATED_DIR}/macos"; fi
115+
if [ -d "${GENERATED_DIR}/catalyst" ]; then rm -rf "${GENERATED_DIR}/catalyst"; fi
92116
if [ -d "${GENERATED_DIR}/simulator" ]; then rm -rf "${GENERATED_DIR}/simulator"; fi
93117
if [ -d ${HEADERS_DIR} ]; then rm -rf ${HEADERS_DIR}; fi
94118

0 commit comments

Comments
 (0)