Skip to content

Commit

Permalink
fix(ios): do not provide arch on xcodebuild when running build and ar…
Browse files Browse the repository at this point in the history
…chive (#353)

* feat: add option to opt out of specifying arch on build and archive

xcodebuild specifies that when passed, the arch option will be used for every single target within the project / workspace.
This can prevent more complex use cases where modifications have been made to the project's build settings.

Rather than modifying the default behavior, offer a way to fallback to project configuration for those cases

* never add -arch on iOS

---------

Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
mrguiman and lucasfernog authored Aug 19, 2024
1 parent 530e7f4 commit b1c2313
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/xcodebuild-remove-arch-arg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": patch
---

Do not include the target arch when building and archiving the iOS application.
20 changes: 16 additions & 4 deletions src/apple/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ impl<'a> Target<'a> {
let scheme = config.scheme();
let workspace_path = config.workspace_path();
let sdk = self.sdk.to_string();
let arch = self.arch.to_string();
let arch = if self.is_macos() {
Some(self.arch.to_string())
} else {
None
};
let args: Vec<OsString> = vec![];
duct::cmd("xcodebuild", args)
.full_env(env.explicit_env())
Expand All @@ -330,12 +334,14 @@ impl<'a> Target<'a> {
if let Some(v) = verbosity(noise_level) {
cmd.arg(v);
}
if let Some(a) = &arch {
cmd.args(["-arch", a]);
}
cmd.args(["-scheme", &scheme])
.arg("-workspace")
.arg(&workspace_path)
.args(["-sdk", &sdk])
.args(["-configuration", configuration])
.args(["-arch", &arch])
.arg("-allowProvisioningUpdates")
.arg("build");
Ok(())
Expand Down Expand Up @@ -371,20 +377,26 @@ impl<'a> Target<'a> {
let scheme = config.scheme();
let workspace_path = config.workspace_path();
let sdk = self.sdk.to_string();
let arch = self.arch.to_string();
let arch = if self.is_macos() {
Some(self.arch.to_string())
} else {
None
};
let args: Vec<OsString> = vec![];
duct::cmd("xcodebuild", args)
.full_env(env.explicit_env())
.before_spawn(move |cmd| {
if let Some(v) = verbosity(noise_level) {
cmd.arg(v);
}
if let Some(a) = &arch {
cmd.args(["-arch", a]);
}
cmd.args(["-scheme", &scheme])
.arg("-workspace")
.arg(&workspace_path)
.args(["-sdk", &sdk])
.args(["-configuration", configuration])
.args(["-arch", &arch])
.arg("-allowProvisioningUpdates")
.arg("archive")
.arg("-archivePath")
Expand Down
2 changes: 1 addition & 1 deletion src/os/macos/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const kLSRolesNone: LSRolesMask = 0x00000001;
pub const kLSRolesViewer: LSRolesMask = 0x00000002;
pub const kLSRolesEditor: LSRolesMask = 0x00000004;
pub const kLSRolesShell: LSRolesMask = 0x00000008;
pub const kLSRolesAll: LSRolesMask = LSRolesMask::max_value();
pub const kLSRolesAll: LSRolesMask = LSRolesMask::MAX;

// https://developer.apple.com/documentation/coreservices/lslaunchflags?language=objc
pub type LSLaunchFlags = OptionBits;
Expand Down

0 comments on commit b1c2313

Please sign in to comment.