fix: building in release mode for simulator (#30543)

Summary:
Fixes https://github.com/facebook/react-native/issues/29984

Right now, running a React Native application with Xcode 12 in Release mode on an iPhone Simulator will fail with something like below:

> [some file path], building for iOS Simulator, but linking in object file built for iOS, file '[some file path]' for architecture arm64

The best explanation of this issue has been provided by alloy in https://github.com/facebook/react-native/issues/29984:

> This issue has started coming up with Xcode 12 and support for the new ARM based Macs, as `arm64` now no longer can be assumed to _only_ be for iOS devices. This means Xcode 12 will now also build for `arm64` simulator SDKs and it has become ambiguous if an arch slice in a prebuilt binary is meant for a simulator or device.
>
> In any case, for now this means that you can configure your Xcode project to exclude `arm64` when building for any iOS simulator SDK.

This PR implements aforementioned workaround.

## Changelog

[FIX] [IOS] - Fix running React Native project with Xcode 12 in Release on iPhone Simulator

Pull Request resolved: https://github.com/facebook/react-native/pull/30543

Test Plan: Switch your scheme to Release and run the app on simulator. Will complete w/o issues.

Reviewed By: appden

Differential Revision: D25537295

Pulled By: TheSavior

fbshipit-source-id: 2dc05cb80e59f1d95d2a84ab55ed6a5b5446411c
This commit is contained in:
Mike Grabowski
2020-12-15 10:47:48 +01:00
parent 2ba3ef5b19
commit 5c09b3fb5b
2 changed files with 31 additions and 4 deletions
+21
View File
@@ -108,3 +108,24 @@ def flipper_post_install(installer)
end
end
end
def react_native_post_install(installer)
projects = installer.aggregate_targets
.map{ |t| t.user_project }
.uniq{ |p| p.path }
.push(installer.pods_project)
arm_value = `/usr/sbin/sysctl -n hw.optional.arm64 2>&1`.to_i
projects.each do |project|
project.build_configurations.each do |config|
if arm_value == 1 then
config.build_settings.delete("EXCLUDED_ARCHS[sdk=iphonesimulator*]")
else
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
project.save()
end
end
+10 -4
View File
@@ -20,9 +20,15 @@ target 'HelloWorld' do
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
use_flipper!
# you should disable the next line.
use_flipper!()
post_install do |installer|
flipper_post_install(installer)
react_native_post_install(installer)
# Enables Flipper.
#
# Disable the next line if you are not using Flipper.
flipper_post_install(installer)
end
end
end