From 40e3d40ea4cf88108346a34edca6f4c15b3f9424 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 14 May 2024 13:43:22 +0200 Subject: [PATCH] reduce build time of CI check --- .github/workflows/bindings_ci.yml | 2 +- bindings/apple/build_crypto_xcframework.sh | 121 ++++++++++++++------- 2 files changed, 81 insertions(+), 42 deletions(-) diff --git a/.github/workflows/bindings_ci.yml b/.github/workflows/bindings_ci.yml index 7cf537530e0..d6a98208d19 100644 --- a/.github/workflows/bindings_ci.yml +++ b/.github/workflows/bindings_ci.yml @@ -147,7 +147,7 @@ jobs: save-if: ${{ github.ref == 'refs/heads/main' }} - name: Run the Build Framework script - run: ./bindings/apple/build_crypto_xcframework.sh + run: ./bindings/apple/build_crypto_xcframework.sh -i - name: Is XCFramework generated? if: ${{ hashFiles('generated/MatrixSDKCryptoFFI.zip') != '' }} diff --git a/bindings/apple/build_crypto_xcframework.sh b/bindings/apple/build_crypto_xcframework.sh index 84b5df8891e..486854847ec 100755 --- a/bindings/apple/build_crypto_xcframework.sh +++ b/bindings/apple/build_crypto_xcframework.sh @@ -1,6 +1,22 @@ #!/usr/bin/env bash set -eEu +helpFunction() { + echo "" + echo "Usage: $0 -only_ios" + echo -e "\t-i Option to build only for iOS. Default will build for all targets." + exit 1 +} + +only_ios='false' + +while getopts ':i' 'opt'; do + case ${opt} in + 'i') only_ios='true' ;; + ?) helpFunction ;; + esac +done + cd "$(dirname "$0")" # Path to the repo root @@ -22,42 +38,59 @@ TARGET_CRATE=matrix-sdk-crypto-ffi # Required by olm-sys crate export IOS_SDK_PATH=`xcrun --show-sdk-path --sdk iphoneos` -# iOS -echo -e "Building for iOS [1/5]" -cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios" - -# MacOS -echo -e "\nBuilding for macOS (Apple Silicon) [2/5]" -cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-darwin" -echo -e "\nBuilding for macOS (Intel) [3/5]" -cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-darwin" - -# iOS Simulator -echo -e "\nBuilding for iOS Simulator (Apple Silicon) [4/5]" -cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios-sim" -echo -e "\nBuilding for iOS Simulator (Intel) [5/5]" -cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-ios" +if ${only_ios}; then + # iOS + echo -e "Building only for iOS" + cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios" +else + # iOS + echo -e "Building for iOS [1/5]" + cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios" + + # MacOS + echo -e "\nBuilding for macOS (Apple Silicon) [2/5]" + cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-darwin" + echo -e "\nBuilding for macOS (Intel) [3/5]" + cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-darwin" + + # iOS Simulator + echo -e "\nBuilding for iOS Simulator (Apple Silicon) [4/5]" + cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios-sim" + echo -e "\nBuilding for iOS Simulator (Intel) [5/5]" + cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-ios" +fi echo -e "\nCreating XCFramework" # Lipo together the libraries for the same platform -# MacOS -lipo -create \ - "${TARGET_DIR}/x86_64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ - "${TARGET_DIR}/aarch64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ - -output "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a" - -# iOS Simulator -lipo -create \ - "${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ - "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ - -output "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" - -# Generate uniffi files -cd ../matrix-sdk-crypto-ffi && cargo run --bin matrix_sdk_crypto_ffi generate \ - --language swift \ - --library "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ - --out-dir ${GENERATED_DIR} +if [ !${only_ios} ]; then + echo "Lipo together the libraries for the same platform" + # MacOS + lipo -create \ + "${TARGET_DIR}/x86_64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + "${TARGET_DIR}/aarch64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + -output "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a" + + # iOS Simulator + lipo -create \ + "${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + -output "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" +fi + +if ${only_ios}; then + # Generate uniffi files + cd ../matrix-sdk-crypto-ffi && cargo run --bin matrix_sdk_crypto_ffi generate \ + --language swift \ + --library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + --out-dir ${GENERATED_DIR} +else + # Generate uniffi files + cd ../matrix-sdk-crypto-ffi && cargo run --bin matrix_sdk_crypto_ffi generate \ + --language swift \ + --library "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + --out-dir ${GENERATED_DIR} +fi # Move headers to the right place HEADERS_DIR=${GENERATED_DIR}/headers @@ -76,15 +109,21 @@ mv ${GENERATED_DIR}/*.swift ${SWIFT_DIR} # Build the xcframework if [ -d "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework" ]; then rm -rf "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework"; fi - -xcodebuild -create-xcframework \ - -library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ - -headers ${HEADERS_DIR} \ - -library "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a" \ - -headers ${HEADERS_DIR} \ - -library "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" \ - -headers ${HEADERS_DIR} \ - -output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework" +if ${only_ios}; then + xcodebuild -create-xcframework \ + -library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + -headers ${HEADERS_DIR} \ + -output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework" +else + xcodebuild -create-xcframework \ + -library "${TARGET_DIR}/aarch64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + -headers ${HEADERS_DIR} \ + -library "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a" \ + -headers ${HEADERS_DIR} \ + -library "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" \ + -headers ${HEADERS_DIR} \ + -output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework" +fi # Cleanup if [ -d "${GENERATED_DIR}/macos" ]; then rm -rf "${GENERATED_DIR}/macos"; fi