Skip to content

Commit

Permalink
fix: building in release mode for simulator (#30543)
Browse files Browse the repository at this point in the history
Summary:
Fixes #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 #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: #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
  • Loading branch information
grabbou committed Dec 15, 2020
1 parent 2ba3ef5 commit 5c09b3f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
21 changes: 21 additions & 0 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 10 additions & 4 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5c09b3f

Please sign in to comment.