Skip to content

Commit 0f8fc53

Browse files
authored
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.
1 parent be3af5e commit 0f8fc53

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

.github/workflows/bindings_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ jobs:
175175
run: swift test
176176

177177
- name: Build Framework
178-
run: target/debug/xtask swift build-framework --target=aarch64-apple-ios --profile=reldbg
178+
run: target/debug/xtask swift build-framework --target=aarch64-apple-ios --profile=dev --ios-deployment-target=18.0
179179

180180
complement-crypto:
181181
name: "Run Complement Crypto tests"

xtask/src/swift.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ enum SwiftCommand {
4343
#[clap(long)]
4444
components_path: Option<Utf8PathBuf>,
4545

46+
/// The iOS deployment target to use when building the framework.
47+
///
48+
/// Defaults to not being set, which implies that the build will use the
49+
/// default values provided by the Rust and Xcode toolchains.
50+
#[clap(long)]
51+
ios_deployment_target: Option<String>,
52+
4653
/// Build the targets one by one instead of passing all of them
4754
/// to cargo in one go, which makes it hang on lesser devices like plain
4855
/// Apple Silicon M1s
@@ -64,12 +71,19 @@ impl SwiftArgs {
6471
components_path,
6572
target: targets,
6673
sequentially,
74+
ios_deployment_target,
6775
} => {
6876
// The dev profile seems to cause crashes on some platforms so we default to
6977
// reldbg (https://github.com/matrix-org/matrix-rust-sdk/issues/4009)
7078
let profile =
7179
profile.as_deref().unwrap_or(if release { "release" } else { "reldbg" });
72-
build_xcframework(profile, targets, components_path, sequentially)
80+
build_xcframework(
81+
profile,
82+
targets,
83+
components_path,
84+
sequentially,
85+
ios_deployment_target.as_deref(),
86+
)
7387
}
7488
}
7589
}
@@ -180,6 +194,7 @@ fn build_xcframework(
180194
targets: Option<Vec<String>>,
181195
components_path: Option<Utf8PathBuf>,
182196
sequentially: bool,
197+
ios_deployment_target: Option<&str>,
183198
) -> Result<()> {
184199
let root_dir = workspace::root_path()?;
185200
let apple_dir = root_dir.join("bindings/apple");
@@ -207,7 +222,8 @@ fn build_xcframework(
207222
TARGETS.iter().collect()
208223
};
209224

210-
let platform_build_paths = build_targets(targets, profile, sequentially)?;
225+
let platform_build_paths =
226+
build_targets(targets, profile, sequentially, ios_deployment_target)?;
211227
let libs = lipo_platform_libraries(&platform_build_paths, &generated_dir)?;
212228

213229
println!("-- Generating uniffi files");
@@ -275,8 +291,18 @@ fn build_targets(
275291
targets: Vec<&Target>,
276292
profile: &str,
277293
sequentially: bool,
294+
ios_deployment_target: Option<&str>,
278295
) -> Result<HashMap<Platform, Vec<Utf8PathBuf>>> {
279296
let sh = sh();
297+
298+
// Note: `push_env` stores environment variables and returns a RAII guard that
299+
// will restore the environment variable to its previous value when dropped.
300+
let _env_guard1 =
301+
sh.push_env("CARGO_TARGET_AARCH64_APPLE_IOS_RUSTFLAGS", "-Clinker=/usr/bin/clang");
302+
let _env_guard2 = sh.push_env("AARCH64_APPLE_IOS_CC", "/usr/bin/clang");
303+
let _env_guard3 =
304+
ios_deployment_target.map(|target| sh.push_env("IPHONEOS_DEPLOYMENT_TARGET", target));
305+
280306
if sequentially {
281307
for target in &targets {
282308
let triple = target.triple;

0 commit comments

Comments
 (0)