From ac4ddec542febda744de218dae3a3d34edc7da84 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Wed, 1 Sep 2021 00:15:04 -0700 Subject: [PATCH] OSS: add Xcode 12.5 + M1 machines CocoaPods post_install workaround Summary: Context: there are multiple issues currently exposed by Xcode 12.5 and/or M1 machine + Flipper. To unblock the new 0.66 release, let's add this workaround in the official react_native_pods.rb recipe and make RNTester and new app Podfile's call it directly. Changelog: [iOS][Fixed] Added workaround for Xcode 12.5 / M1 machines build issues Reviewed By: lunaleaps Differential Revision: D30691291 fbshipit-source-id: 8b24cc60da3d620dbc90f95c77f2345e18c28212 --- packages/rn-tester/Podfile | 1 + scripts/react_native_pods.rb | 35 +++++++++++++++++++++++++++++++++++ template/ios/Podfile | 1 + 3 files changed, 37 insertions(+) diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index dcc05865ac59d1..b7492364d7204e 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -61,4 +61,5 @@ end post_install do |installer| react_native_post_install(installer) + __apply_Xcode_12_5_M1_post_install_workaround(installer) end diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 02b04e1e4f7542..2325ad33c57437 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -212,3 +212,38 @@ def use_react_native_codegen!(spec, options={}) :show_env_vars_in_log => true } end + +# This provides a post_install workaround for build issues related Xcode 12.5 and Apple Silicon (M1) machines. +# Call this in the app's main Podfile's post_install hook. +# See https://github.com/facebook/react-native/issues/31480#issuecomment-902912841 for more context. +# Actual fix was authored by https://github.com/mikehardy. +# New app template will call this for now until the underlying issue is resolved. +def __apply_Xcode_12_5_M1_post_install_workaround(installer) + # Apple Silicon builds require a library path tweak for Swift library discovery to resolve Swift-related "symbol not found". + # Note: this was fixed via https://github.com/facebook/react-native/commit/eb938863063f5535735af2be4e706f70647e5b90 + # Keeping this logic here but commented out for future reference. + # + # installer.aggregate_targets.each do |aggregate_target| + # aggregate_target.user_project.native_targets.each do |target| + # target.build_configurations.each do |config| + # config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(inherited)'] + # end + # end + # aggregate_target.user_project.save + # end + + # Flipper podspecs are still targeting an older iOS deployment target, and may cause an error like: + # "error: thread-local storage is not supported for the current target" + # The most reliable known workaround is to bump iOS deployment target to match react-native (iOS 11 now). + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' + end + end + + # But... doing so caused another issue in Flipper: + # "Time.h:52:17: error: typedef redefinition with different types" + # We need to make a patch to RCT-Folly - set `__IPHONE_10_0` to our iOS target + 1. + # See https://github.com/facebook/flipper/issues/834 for more details. + `sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h` +end diff --git a/template/ios/Podfile b/template/ios/Podfile index 65d5ffcbfcf420..9409747f917830 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -25,5 +25,6 @@ target 'HelloWorld' do post_install do |installer| react_native_post_install(installer) + __apply_Xcode_12_5_M1_post_install_workaround(installer) end end