From 929f992eb9560bed95886bcadc17480a70f2f06f Mon Sep 17 00:00:00 2001 From: Brian M Date: Thu, 11 May 2023 19:37:03 -0700 Subject: [PATCH 1/3] feat: compile framework for mac catalyst --- bindings/apple/build_crypto_xcframework.sh | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/bindings/apple/build_crypto_xcframework.sh b/bindings/apple/build_crypto_xcframework.sh index 10c7818de4e..5b39c715447 100755 --- a/bindings/apple/build_crypto_xcframework.sh +++ b/bindings/apple/build_crypto_xcframework.sh @@ -10,7 +10,7 @@ TARGET_DIR="${SRC_ROOT}/target" GENERATED_DIR="${SRC_ROOT}/generated" if [ -d "${GENERATED_DIR}" ]; then rm -rf "${GENERATED_DIR}"; fi -mkdir -p ${GENERATED_DIR}/{macos,simulator} +mkdir -p ${GENERATED_DIR}/{macos,simulator,catalyst} REL_FLAG="--release" REL_TYPE_DIR="release" @@ -19,23 +19,38 @@ TARGET_CRATE=matrix-sdk-crypto-ffi # Build static libs for all the different architectures -# Required by olm-sys crate +# Required by olm-sys crate. @todo: Is this the right SDK path for Catalyst as well? export IOS_SDK_PATH=`xcrun --show-sdk-path --sdk iphoneos` # iOS -echo -e "Building for iOS [1/5]" +echo -e "Building for iOS [1/7]" cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios" +# Mac Catalyst +# 1) The target has no pre=built rust-std, so we use `-Z build-std`. +# how to build-std: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std +# list of targets with prebuilt rust-std: https://doc.rust-lang.org/nightly/rustc/platform-support.html +# 2) requires a recent nightly wih https://github.com/rust-lang/rust/pull/111384 merged +CATALYST_RUST_NIGHTLY="nightly" +echo -e "\nInstalling nightly and rust-src for Mac Catalyst" +rustup toolchain install ${CATALYST_RUST_NIGHTLY} --no-self-update +rustup component add rust-src --toolchain ${CATALYST_RUST_NIGHTLY} + +echo -e "\nBuilding for macOS Catalyst (Apple Silicon) [2/7]" +cargo +${CATALYST_RUST_NIGHTLY} build -p ${TARGET_CRATE} ${REL_FLAG} -Z build-std --target aarch64-apple-ios-macabi +echo -e "\nBuilding for macOS Catalyst (Intel) [3/7]" +cargo +${CATALYST_RUST_NIGHTLY} build -p ${TARGET_CRATE} ${REL_FLAG} -Z build-std --target x86_64-apple-ios-macabi + # MacOS -echo -e "\nBuilding for macOS (Apple Silicon) [2/5]" +echo -e "\nBuilding for macOS (Apple Silicon) [4/7]" cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-darwin" -echo -e "\nBuilding for macOS (Intel) [3/5]" +echo -e "\nBuilding for macOS (Intel) [5/7]" cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-darwin" # iOS Simulator -echo -e "\nBuilding for iOS Simulator (Apple Silicon) [4/5]" +echo -e "\nBuilding for iOS Simulator (Apple Silicon) [6/7]" cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "aarch64-apple-ios-sim" -echo -e "\nBuilding for iOS Simulator (Intel) [5/5]" +echo -e "\nBuilding for iOS Simulator (Intel) [7/7]" cargo build -p ${TARGET_CRATE} ${REL_FLAG} --target "x86_64-apple-ios" echo -e "\nCreating XCFramework" @@ -47,6 +62,12 @@ lipo -create \ "${TARGET_DIR}/aarch64-apple-darwin/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ -output "${GENERATED_DIR}/macos/libmatrix_sdk_crypto_ffi.a" +# Catalyst +lipo -create \ + "${TARGET_DIR}/aarch64-apple-ios-macabi/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + "${TARGET_DIR}/x86_64-apple-ios-macabi/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ + -output "${GENERATED_DIR}/catalyst/libmatrix_sdk_crypto_ffi.a" + # iOS Simulator lipo -create \ "${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \ @@ -85,10 +106,13 @@ xcodebuild -create-xcframework \ -headers ${HEADERS_DIR} \ -library "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a" \ -headers ${HEADERS_DIR} \ + -library "${GENERATED_DIR}/catalyst/libmatrix_sdk_crypto_ffi.a" \ + -headers ${HEADERS_DIR} \ -output "${GENERATED_DIR}/MatrixSDKCryptoFFI.xcframework" # Cleanup if [ -d "${GENERATED_DIR}/macos" ]; then rm -rf "${GENERATED_DIR}/macos"; fi +if [ -d "${GENERATED_DIR}/catalyst" ]; then rm -rf "${GENERATED_DIR}/catalyst"; fi if [ -d "${GENERATED_DIR}/simulator" ]; then rm -rf "${GENERATED_DIR}/simulator"; fi if [ -d ${HEADERS_DIR} ]; then rm -rf ${HEADERS_DIR}; fi From 6119d19f14fb770761c5107e2f49d977ae77cde4 Mon Sep 17 00:00:00 2001 From: Brian M Date: Tue, 30 May 2023 19:28:23 -0700 Subject: [PATCH 2/3] update xtask --- xtask/src/swift.rs | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/xtask/src/swift.rs b/xtask/src/swift.rs index 5a422c4e9d7..6536d94fc9c 100644 --- a/xtask/src/swift.rs +++ b/xtask/src/swift.rs @@ -115,7 +115,15 @@ fn generate_uniffi(library_file: &Path, ffi_directory: &Path) -> Result<()> { } fn build_for_target(target: &str, profile: &str) -> Result { - cmd!("cargo build -p matrix-sdk-ffi --target {target} --profile {profile}").run()?; + let is_catalyst = target.ends_with("-macabi"); + if is_catalyst { + const CATALYST_RUST_NIGHTLY: &str = "nightly"; + cmd!("rustup toolchain install {CATALYST_RUST_NIGHTLY} --no-self-update").run()?; + cmd!("rustup component add rust-src --toolchain {CATALYST_RUST_NIGHTLY}").run()?; + cmd!("cargo +{CATALYST_RUST_NIGHTLY} build -p matrix-sdk-ffi -Z build-std --target {target} --profile {profile}").run()?; + } else { + cmd!("cargo build -p matrix-sdk-ffi --target {target} --profile {profile}").run()?; + } // The builtin dev profile has its files stored under target/debug, all // other targets have matching directory names @@ -147,20 +155,25 @@ fn build_xcframework( (vec![build_path.clone()], build_path) } else { - println!("-- Building for iOS [1/5]"); + println!("-- Building for iOS [1/7]"); let ios_path = build_for_target("aarch64-apple-ios", profile)?; - println!("-- Building for macOS (Apple Silicon) [2/5]"); + println!("-- Building for macOS (Apple Silicon) [2/7]"); let darwin_arm_path = build_for_target("aarch64-apple-darwin", profile)?; - println!("-- Building for macOS (Intel) [3/5]"); + println!("-- Building for macOS (Intel) [3/7]"); let darwin_x86_path = build_for_target("x86_64-apple-darwin", profile)?; - println!("-- Building for iOS Simulator (Apple Silicon) [4/5]"); + println!("-- Building for Mac Catalyst (Apple Silicon) [4/7]"); + let catalyst_arm_path = build_for_target("aarch64-apple-ios-macabi", profile)?; + println!("-- Building for Mac Catalyst (Intel) [5/7]"); + let catalyst_x86_path = build_for_target("x86_64-apple-ios-macabi", profile)?; + + println!("-- Building for iOS Simulator (Apple Silicon) [6/7]"); let ios_sim_arm_path = build_for_target("aarch64-apple-ios-sim", profile)?; - println!("-- Building for iOS Simulator (Intel) [5/5]"); + println!("-- Building for iOS Simulator (Intel) [7/7]"); let ios_sim_x86_path = build_for_target("x86_64-apple-ios", profile)?; - println!("-- Running Lipo for macOS [1/2]"); + println!("-- Running Lipo for macOS [1/3]"); // # macOS let lipo_target_macos = generated_dir.join("libmatrix_sdk_ffi_macos.a"); cmd!( @@ -169,7 +182,16 @@ fn build_xcframework( ) .run()?; - println!("-- Running Lipo for iOS Simulator [2/2]"); + println!("-- Running Lipo for Mac Catalyst [2/3]"); + // # Catalyst + let lipo_target_catalyst = generated_dir.join("libmatrix_sdk_ffi_catalyst.a"); + cmd!( + "lipo -create {catalyst_x86_path} {catalyst_arm_path} + -output {lipo_target_catalyst}" + ) + .run()?; + + println!("-- Running Lipo for iOS Simulator [3/3]"); // # iOS Simulator let lipo_target_sim = generated_dir.join("libmatrix_sdk_ffi_iossimulator.a"); cmd!( @@ -177,7 +199,7 @@ fn build_xcframework( -output {lipo_target_sim}" ) .run()?; - (vec![lipo_target_macos, lipo_target_sim, ios_path], darwin_x86_path) + (vec![lipo_target_macos, lipo_target_catalyst, lipo_target_sim, ios_path], darwin_x86_path) }; println!("-- Generating uniffi files"); From d5a35c9fa28eaea335abe59a804839a01c10348c Mon Sep 17 00:00:00 2001 From: Brian M Date: Tue, 30 May 2023 19:47:33 -0700 Subject: [PATCH 3/3] upgrade log for value-bag@1.4 which fixes nightly Previous versions of log used an alpha version of value-bag, which broke on the new nightly rustc: https://github.com/rust-lang/rust/issues/77125 --- Cargo.lock | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d68aeeeda99..511f9598838 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1114,16 +1114,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "ctor" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" -dependencies = [ - "quote", - "syn 1.0.109", -] - [[package]] name = "ctor" version = "0.2.0" @@ -2463,11 +2453,10 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" dependencies = [ - "cfg-if", "value-bag", ] @@ -2557,7 +2546,7 @@ dependencies = [ "backoff", "bytes", "bytesize", - "ctor 0.2.0", + "ctor", "dashmap", "dirs", "event-listener", @@ -2631,7 +2620,7 @@ dependencies = [ "assign", "async-trait", "bitflags 2.3.0", - "ctor 0.2.0", + "ctor", "dashmap", "eyeball", "futures-executor", @@ -2684,7 +2673,7 @@ dependencies = [ "byteorder", "cbc", "cfg-if", - "ctor 0.2.0", + "ctor", "ctr", "dashmap", "eyeball", @@ -2861,7 +2850,7 @@ version = "0.1.0" dependencies = [ "anyhow", "assign", - "ctor 0.2.0", + "ctor", "matrix-sdk", "once_cell", "tempfile", @@ -2913,7 +2902,7 @@ version = "0.1.0" dependencies = [ "assert_matches", "async-trait", - "ctor 0.2.0", + "ctor", "deadpool-sqlite", "glob", "matrix-sdk-base", @@ -2984,7 +2973,7 @@ dependencies = [ "assert_matches", "async-trait", "chrono", - "ctor 0.2.0", + "ctor", "eyeball-im", "futures-core", "futures-util", @@ -3120,7 +3109,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49ac8112fe5998579b22e29903c7b277fc7f91c7860c0236f35792caf8156e18" dependencies = [ "bitflags 2.3.0", - "ctor 0.2.0", + "ctor", "napi-derive", "napi-sys", "once_cell", @@ -5685,13 +5674,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.0.0-alpha.9" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" -dependencies = [ - "ctor 0.1.26", - "version_check", -] +checksum = "a4d330786735ea358f3bc09eea4caa098569c1c93f342d9aca0514915022fe7e" [[package]] name = "vcpkg"