From 0f8fc53019f1f4f58d99830cbb2a4a37789ce6d7 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 2 Jul 2025 14:20:53 +0200 Subject: [PATCH] chore(ci): use the dev profile when building the swift bindings (#5328) The swift bindings aren't getting tested (they don't run) in CI anymore, so building with the reldbg profile (that's a workaround to make it run and not crash in production) doesn't provide more value than building in debug mode, while taking much longer to build. Let's use the default dev profile for this; we have to specify it manually, because the default for the xtask command is to use the `reldbg` profile otherwise. This requires a fix for the dev profile, that consists in being able to set the iOS deployment target, and set it to a high value in CI settings. Production builds *don't* have to set it, though. --- .github/workflows/bindings_ci.yml | 2 +- xtask/src/swift.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bindings_ci.yml b/.github/workflows/bindings_ci.yml index 024c89d86..7a89c4e84 100644 --- a/.github/workflows/bindings_ci.yml +++ b/.github/workflows/bindings_ci.yml @@ -175,7 +175,7 @@ jobs: run: swift test - name: Build Framework - run: target/debug/xtask swift build-framework --target=aarch64-apple-ios --profile=reldbg + run: target/debug/xtask swift build-framework --target=aarch64-apple-ios --profile=dev --ios-deployment-target=18.0 complement-crypto: name: "Run Complement Crypto tests" diff --git a/xtask/src/swift.rs b/xtask/src/swift.rs index 6c5c790bf..fe3b1ef3e 100644 --- a/xtask/src/swift.rs +++ b/xtask/src/swift.rs @@ -43,6 +43,13 @@ enum SwiftCommand { #[clap(long)] components_path: Option, + /// The iOS deployment target to use when building the framework. + /// + /// Defaults to not being set, which implies that the build will use the + /// default values provided by the Rust and Xcode toolchains. + #[clap(long)] + ios_deployment_target: Option, + /// Build the targets one by one instead of passing all of them /// to cargo in one go, which makes it hang on lesser devices like plain /// Apple Silicon M1s @@ -64,12 +71,19 @@ impl SwiftArgs { components_path, target: targets, sequentially, + ios_deployment_target, } => { // The dev profile seems to cause crashes on some platforms so we default to // reldbg (https://github.com/matrix-org/matrix-rust-sdk/issues/4009) let profile = profile.as_deref().unwrap_or(if release { "release" } else { "reldbg" }); - build_xcframework(profile, targets, components_path, sequentially) + build_xcframework( + profile, + targets, + components_path, + sequentially, + ios_deployment_target.as_deref(), + ) } } } @@ -180,6 +194,7 @@ fn build_xcframework( targets: Option>, components_path: Option, sequentially: bool, + ios_deployment_target: Option<&str>, ) -> Result<()> { let root_dir = workspace::root_path()?; let apple_dir = root_dir.join("bindings/apple"); @@ -207,7 +222,8 @@ fn build_xcframework( TARGETS.iter().collect() }; - let platform_build_paths = build_targets(targets, profile, sequentially)?; + let platform_build_paths = + build_targets(targets, profile, sequentially, ios_deployment_target)?; let libs = lipo_platform_libraries(&platform_build_paths, &generated_dir)?; println!("-- Generating uniffi files"); @@ -275,8 +291,18 @@ fn build_targets( targets: Vec<&Target>, profile: &str, sequentially: bool, + ios_deployment_target: Option<&str>, ) -> Result>> { let sh = sh(); + + // Note: `push_env` stores environment variables and returns a RAII guard that + // will restore the environment variable to its previous value when dropped. + let _env_guard1 = + sh.push_env("CARGO_TARGET_AARCH64_APPLE_IOS_RUSTFLAGS", "-Clinker=/usr/bin/clang"); + let _env_guard2 = sh.push_env("AARCH64_APPLE_IOS_CC", "/usr/bin/clang"); + let _env_guard3 = + ios_deployment_target.map(|target| sh.push_env("IPHONEOS_DEPLOYMENT_TARGET", target)); + if sequentially { for target in &targets { let triple = target.triple;