Skip to content

Commit 60cf1ea

Browse files
authored
fix(apple): simulator build on Intel machines (#479)
* fix(apple): simulator build on Intel machines ref tauri-apps/tauri#13456 * ARCHS instead of -arch * use iphone 13 for swiftCompatibilityConcurrency? * change file
1 parent c0c0738 commit 60cf1ea

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cargo-mobile2": patch
3+
---
4+
5+
Fix build and archive not working on Apple Intel systems when targeting the simulator.

src/apple/target.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,18 @@ impl<'a> Target<'a> {
524524
None
525525
};
526526

527-
let destination = target_device.map(|device| format!("id={}", device.id()));
527+
let destination = target_device
528+
.map(|device| format!("id={}", device.id()))
529+
.or_else(|| {
530+
if cfg!(target_arch = "x86_64") && self.sdk == "iphonesimulator" {
531+
// on Intel we must force the destination when targeting the simulator
532+
// otherwise xcodebuild tries to build arm64
533+
// iPhone 13 seems like a good default target, old enough for every Xcode out there to have it?
534+
Some("platform=iOS Simulator,name=iPhone 13".to_string())
535+
} else {
536+
None
537+
}
538+
});
528539

529540
let args: Vec<OsString> = vec![];
530541
duct::cmd("xcodebuild", args)
@@ -541,6 +552,12 @@ impl<'a> Target<'a> {
541552
cmd.args(["-destination", destination]);
542553
}
543554

555+
if cfg!(target_arch = "x86_64") && sdk == "iphonesimulator" {
556+
// on Intel we must force the ARCHS when targeting the simulator
557+
// otherwise xcodebuild tries to build arm64
558+
cmd.arg("ARCHS=x86_64");
559+
}
560+
544561
cmd.args(["-scheme", &scheme])
545562
.arg("-workspace")
546563
.arg(&workspace_path)
@@ -588,6 +605,7 @@ impl<'a> Target<'a> {
588605
} else {
589606
None
590607
};
608+
591609
let args: Vec<OsString> = vec![];
592610
duct::cmd("xcodebuild", args)
593611
.full_env(env.explicit_env())
@@ -600,6 +618,15 @@ impl<'a> Target<'a> {
600618
if let Some(a) = &arch {
601619
cmd.args(["-arch", a]);
602620
}
621+
622+
if cfg!(target_arch = "x86_64") && sdk == "iphonesimulator" {
623+
// on Intel we must force the ARCHS and destination when targeting the simulator
624+
// otherwise xcodebuild tries to build arm64
625+
// iPhone 13 seems like a good default target, old enough for every Xcode out there to have it?
626+
cmd.args(["-destination", "platform=iOS Simulator,name=iPhone 13"])
627+
.arg("ARCHS=x86_64");
628+
}
629+
603630
cmd.args(["-scheme", &scheme])
604631
.arg("-workspace")
605632
.arg(&workspace_path)

0 commit comments

Comments
 (0)