From 60cf1eae5cbc1c815da3685559c59f06b3be6286 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Thu, 28 Aug 2025 17:56:53 -0300 Subject: [PATCH] fix(apple): simulator build on Intel machines (#479) * fix(apple): simulator build on Intel machines ref https://github.com/tauri-apps/tauri/issues/13456 * ARCHS instead of -arch * use iphone 13 for swiftCompatibilityConcurrency? * change file --- .changes/fix-simulator-build-intel.md | 5 +++++ src/apple/target.rs | 29 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-simulator-build-intel.md diff --git a/.changes/fix-simulator-build-intel.md b/.changes/fix-simulator-build-intel.md new file mode 100644 index 0000000..87fd110 --- /dev/null +++ b/.changes/fix-simulator-build-intel.md @@ -0,0 +1,5 @@ +--- +"cargo-mobile2": patch +--- + +Fix build and archive not working on Apple Intel systems when targeting the simulator. diff --git a/src/apple/target.rs b/src/apple/target.rs index 01d13a5..feaf183 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -524,7 +524,18 @@ impl<'a> Target<'a> { None }; - let destination = target_device.map(|device| format!("id={}", device.id())); + let destination = target_device + .map(|device| format!("id={}", device.id())) + .or_else(|| { + if cfg!(target_arch = "x86_64") && self.sdk == "iphonesimulator" { + // on Intel we must force the destination when targeting the simulator + // otherwise xcodebuild tries to build arm64 + // iPhone 13 seems like a good default target, old enough for every Xcode out there to have it? + Some("platform=iOS Simulator,name=iPhone 13".to_string()) + } else { + None + } + }); let args: Vec = vec![]; duct::cmd("xcodebuild", args) @@ -541,6 +552,12 @@ impl<'a> Target<'a> { cmd.args(["-destination", destination]); } + if cfg!(target_arch = "x86_64") && sdk == "iphonesimulator" { + // on Intel we must force the ARCHS when targeting the simulator + // otherwise xcodebuild tries to build arm64 + cmd.arg("ARCHS=x86_64"); + } + cmd.args(["-scheme", &scheme]) .arg("-workspace") .arg(&workspace_path) @@ -588,6 +605,7 @@ impl<'a> Target<'a> { } else { None }; + let args: Vec = vec![]; duct::cmd("xcodebuild", args) .full_env(env.explicit_env()) @@ -600,6 +618,15 @@ impl<'a> Target<'a> { if let Some(a) = &arch { cmd.args(["-arch", a]); } + + if cfg!(target_arch = "x86_64") && sdk == "iphonesimulator" { + // on Intel we must force the ARCHS and destination when targeting the simulator + // otherwise xcodebuild tries to build arm64 + // iPhone 13 seems like a good default target, old enough for every Xcode out there to have it? + cmd.args(["-destination", "platform=iOS Simulator,name=iPhone 13"]) + .arg("ARCHS=x86_64"); + } + cmd.args(["-scheme", &scheme]) .arg("-workspace") .arg(&workspace_path)