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.
This commit is contained in:
Benjamin Bouvier
2025-07-02 14:20:53 +02:00
committed by GitHub
parent be3af5e0d4
commit 0f8fc53019
2 changed files with 29 additions and 3 deletions
+1 -1
View File
@@ -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"
+28 -2
View File
@@ -43,6 +43,13 @@ enum SwiftCommand {
#[clap(long)]
components_path: Option<Utf8PathBuf>,
/// 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<String>,
/// 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<Vec<String>>,
components_path: Option<Utf8PathBuf>,
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<HashMap<Platform, Vec<Utf8PathBuf>>> {
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;