From 67d7e0a1f4613c266c1eb1ac5bc04fd57cee8db8 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Thu, 27 Aug 2020 16:40:13 -0700 Subject: [PATCH] flipper (ios): Prepare to enable Flipper. We'll actually enable it in the main RN v0.61 -> v0.62 upgrade commit, if only because running Flipper pre-RN v0.62 isn't advertised as something you can do. Enabling it means calling the initialize function, like in facebook/react-native@05f5cb534, but in the form it took in facebook/react-native@b4d1fcfb2 (and the conditional that appears there). This encompasses several RN commits, as follows, several of which broke builds (which poses a problem even without Flipper enabled). We lump these in with their fixes, so that we don't knowingly introduce errors at any commit in our project. Mostly, these problems can be traced to upgrading the FlipperKit pod and not handling breaking changes at the same time. Generally, though, the RN commits aren't very clear or coherent, so I feel safer flattening all of these even if something could plausibly stand alone in our project. ----- facebook/react-native@70274f4e9 ----- This commit is unstable. One reason is that `pod install` fails until `:modular_headers` is added to the `Yoga` pod declaration in facebook/react-native@898b1db6d. The failure message: ``` [!] The following Swift pods cannot yet be integrated as static libraries: The Swift pod `YogaKit` depends upon `Yoga`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies. ``` ----- facebook/react-native@e8541e03f ----- The claim is that this commit adds running React Dev Tools to the template. I had thought this was something totally separate from Flipper (and so this would naturally stand in its own commit), but no; the added code comes from the `FlipperKitReactPlugin` subspec of the `FlipperKit` pod, and it'll be invoked in the Flipper initialization function. This commit also advances the FlipperKit pod version to v0.23.6; I'm not aware of any new issues that were specifically introduced in this version. Still, seems safest to apply these changes in this giant commit. ----- facebook/react-native@898b1db6d ----- A small handful of changes in `AppDelegate.m`, the Podfile, and `project.pbxproj` are made here. The motivation for the `AppDelegate.m` changes isn't clear to me, unless it's "The integration of Flipper on iOS was crashing the template"--not super descriptive or helpful in finding the origin of the issue. In the Podfile, the addition of `:modular_headers => true` to the `Yoga` pod declaration fixes a `pod install` failure introduced in facebook/react-native@70274f4e9, described above. Also in the Podfile, the change of FlipperKit's version to v0.30.0 introduces a build failure associated with facebook/flipper@ab121f9d9, with Flipper release tag v0.26.0; see https://github.com/facebook/react-native/issues/27565#issuecomment-582490074. That issue was non-optimally resolved in facebook/react-native@b4d1fcfb2, which we'll take for now in this commit (see below); a more principled solution is open as facebook/flipper#1171. The `project.pbxproj` changes here aren't fully explained, but here's what I think happened, and what I did about it: - An empty Swift file was added, to rouse Xcode into being prepared to handle Swift files, which is needed for the "YogaKit" dep; see https://github.com/facebook/react-native/pull/27426#issuecomment-562431325. This step is included in the upgrade guide [1]. The empty Swift file was later backed out in facebook/react-native@e3218a0d9 (see below), which is why it doesn't appear here. - The addition of the empty Swift file activated a wizard that walked the user through setting up an Objective-C "bridging header" file and set some plausibly desired settings in the `project.pbxproj` file. RN deleted the bridging header file, but the settings remained. We had actually already set up a bridging header file a long time ago, in d38129b33, and this setup wizard didn't activate when I created the empty Swift file. I tried to *get* it to activate (to better reproduce the settings changes) by deleting our bridging header file and re-adding the Swift file, but it didn't work. However, the settings that got added in d38129b33 seem to match these settings pretty closely; one notable difference is that a SWIFT_VERSION build setting is 4.2 instead of 5.0. In any case, the upgrade guide on the Xcode changes [1] only says the bridging-header wizard will "most likely" appear, and if it doesn't, just keep going. - They added "English" under `knownRegions` in the project info. We have this already, and, in fact, it gets *removed* if I follow an automatic deprecation fix that Xcode suggests in the buildtime warnings (an instance of #4112). So, ignore this. ----- facebook/react-native@e3218a0d9 ----- This Facebook commit looks fairly coherent, but it's a partial reversion of facebook/react-native@898b1db6d (just above) with a tweak on top of it. So, might as well put it into the same commit. The `project.pbxproj` changes are as follows, as best as I can tell: - The empty Swift file described just above is removed. This is not reflected in the upgrade guide on the Xcode changes [1], which still says you need to create the file. - A `LIBRARY_SEARCH_PATHS` setting is added. This *is* reflected in the upgrade guide on the Xcode changes [1]; following those instructions does indeed generate a portion of the diff. - An `LD_RUNPATH_SEARCH_PATHS` setting is added; this is *not* reflected in the upgrade guide. It's reportedly crucial; see https://github.com/facebook/react-native/pull/27922#discussion_r373720709. I copied the code. - A `DEAD_CODE_STRIPPING` setting is removed; this is *not* reflected in the upgrade guide. Reportedly (and in my experience, as best as I can remember and conclude), it's crucial; see https://github.com/facebook/react-native/pull/27922#discussion_r373727435. I copied the code. ----- facebook/react-native@8f954b365 ----- Just simple prose adjustments to a comment, but it's substantially reworked in facebook/react-native@b4d1fcfb2 (which follows). ----- facebook/react-native@b4d1fcfb2 ----- This looks like a partial reversion of facebook/react-native@898b1db6d (above), with a tweak; the `FB_SONARKIT_ENABLED` conditional is removed from `AppDelegate.m`, but that identifier now appears in the `project.pbxproj`. It also continues the advancement of the FlipperKit pod's version, this time to v0.30.2, and adjusts some comments. ----- facebook/react-native@f6a8452e7 ----- After an upgrade to FlipperKit v0.32.0 in facebook/react-native@ada73a354, quickly reverted in facebook/react-native@4bb17944f, this commit brings us to v0.33.1. ----- facebook/react-native@8858d879e ----- This is the last commit that affects Flipper on iOS before the v0.62 release was made. It doesn't continue the advancement of the FlipperKit version (and a good thing, too, maybe!). It lists several transitive dependencies of FlipperKit pods to the Podfile and gives them each a `:configuration => 'Debug'` setting, and that's it. It appears to be accounting for a CocoaPods quirk that means that, before this change is made, all those dependencies would get included in release builds, increasing the binary size. Might as well avoid having any commits with that increased size; so, conclude this giant commit with these changes. All that's left is to actually enable Flipper, which we'll do in the main upgrade commit. [1] https://github.com/react-native-community/upgrade-support/issues/13 --- ios/Podfile | 55 ++++++++++++- ios/Podfile.lock | 96 ++++++++++++++++++++++- ios/ZulipMobile.xcodeproj/project.pbxproj | 18 ++++- ios/ZulipMobile/AppDelegate.m | 19 +++++ 4 files changed, 185 insertions(+), 3 deletions(-) diff --git a/ios/Podfile b/ios/Podfile index 73ffc388e80..7dd80ddd425 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -5,6 +5,50 @@ platform :ios, '10.3' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' require_relative '../node_modules/react-native-unimodules/cocoapods.rb' +# Add Flipper Pods +def add_flipper_pods!(versions = {}) + versions['Flipper'] ||= '~> 0.33.1' + versions['DoubleConversion'] ||= '1.1.7' + versions['Flipper-Folly'] ||= '~> 2.1' + versions['Flipper-Glog'] ||= '0.3.6' + versions['Flipper-PeerTalk'] ||= '~> 0.0.4' + versions['Flipper-RSocket'] ||= '~> 1.0' + + pod 'FlipperKit', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FlipperKitLayoutPlugin', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/SKIOSNetworkPlugin', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FlipperKitUserDefaultsPlugin', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FlipperKitReactPlugin', versions['Flipper'], :configuration => 'Debug' + + # List all transitive dependencies for FlipperKit pods + # to avoid them being linked in Release builds + pod 'Flipper', versions['Flipper'], :configuration => 'Debug' + pod 'Flipper-DoubleConversion', versions['DoubleConversion'], :configuration => 'Debug' + pod 'Flipper-Folly', versions['Flipper-Folly'], :configuration => 'Debug' + pod 'Flipper-Glog', versions['Flipper-Glog'], :configuration => 'Debug' + pod 'Flipper-PeerTalk', versions['Flipper-PeerTalk'], :configuration => 'Debug' + pod 'Flipper-RSocket', versions['Flipper-RSocket'], :configuration => 'Debug' + pod 'FlipperKit/Core', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/CppBridge', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FBCxxFollyDynamicConvert', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FBDefines', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FKPortForwarding', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FlipperKitHighlightOverlay', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FlipperKitLayoutTextSearchable', versions['Flipper'], :configuration => 'Debug' + pod 'FlipperKit/FlipperKitNetworkPlugin', versions['Flipper'], :configuration => 'Debug' +end + +# Post Install processing for Flipper +def flipper_post_install(installer) + installer.pods_project.targets.each do |target| + if target.name == 'YogaKit' + target.build_configurations.each do |config| + config.build_settings['SWIFT_VERSION'] = '4.1' + end + end + end +end + target 'ZulipMobile' do # Pods from React Native pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" @@ -35,7 +79,7 @@ target 'ZulipMobile' do pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS' pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon" pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" - pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga' + pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' @@ -44,6 +88,15 @@ target 'ZulipMobile' do # Native, unless omitted in our own `react-native.config.js`. use_native_modules! + # Enables Flipper. + # + # Note that if you have use_frameworks! enabled, Flipper will not work and + # you should disable these next few lines. + add_flipper_pods! + post_install do |installer| + flipper_post_install(installer) + end + # unimodules provides Expo packages individually. use_unimodules! end diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 012ee35f1ae..ae5fd23cfa8 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1,5 +1,7 @@ PODS: - boost-for-react-native (1.63.0) + - CocoaAsyncSocket (7.6.4) + - CocoaLibEvent (1.0.0) - DoubleConversion (1.1.6) - EXAppleAuthentication (2.1.1): - UMCore @@ -29,6 +31,52 @@ PODS: - React-Core (= 0.61.5) - React-jsi (= 0.61.5) - ReactCommon/turbomodule/core (= 0.61.5) + - Flipper (0.33.1): + - Flipper-Folly (~> 2.1) + - Flipper-RSocket (~> 1.0) + - Flipper-DoubleConversion (1.1.7) + - Flipper-Folly (2.2.0): + - boost-for-react-native + - CocoaLibEvent (~> 1.0) + - Flipper-DoubleConversion + - Flipper-Glog + - OpenSSL-Universal (= 1.0.2.19) + - Flipper-Glog (0.3.6) + - Flipper-PeerTalk (0.0.4) + - Flipper-RSocket (1.1.0): + - Flipper-Folly (~> 2.2) + - FlipperKit (0.33.1): + - FlipperKit/Core (= 0.33.1) + - FlipperKit/Core (0.33.1): + - Flipper (~> 0.33.1) + - FlipperKit/CppBridge + - FlipperKit/FBCxxFollyDynamicConvert + - FlipperKit/FBDefines + - FlipperKit/FKPortForwarding + - FlipperKit/CppBridge (0.33.1): + - Flipper (~> 0.33.1) + - FlipperKit/FBCxxFollyDynamicConvert (0.33.1): + - Flipper-Folly (~> 2.1) + - FlipperKit/FBDefines (0.33.1) + - FlipperKit/FKPortForwarding (0.33.1): + - CocoaAsyncSocket (~> 7.6) + - Flipper-PeerTalk (~> 0.0.4) + - FlipperKit/FlipperKitHighlightOverlay (0.33.1) + - FlipperKit/FlipperKitLayoutPlugin (0.33.1): + - FlipperKit/Core + - FlipperKit/FlipperKitHighlightOverlay + - FlipperKit/FlipperKitLayoutTextSearchable + - YogaKit (~> 1.18) + - FlipperKit/FlipperKitLayoutTextSearchable (0.33.1) + - FlipperKit/FlipperKitNetworkPlugin (0.33.1): + - FlipperKit/Core + - FlipperKit/FlipperKitReactPlugin (0.33.1): + - FlipperKit/Core + - FlipperKit/FlipperKitUserDefaultsPlugin (0.33.1): + - FlipperKit/Core + - FlipperKit/SKIOSNetworkPlugin (0.33.1): + - FlipperKit/Core + - FlipperKit/FlipperKitNetworkPlugin - Folly (2018.10.22.00): - boost-for-react-native - DoubleConversion @@ -39,6 +87,9 @@ PODS: - DoubleConversion - glog - glog (0.3.5) + - OpenSSL-Universal (1.0.2.19): + - OpenSSL-Universal/Static (= 1.0.2.19) + - OpenSSL-Universal/Static (1.0.2.19) - RCTRequired (0.61.5) - RCTTypeSafety (0.61.5): - FBLazyVector (= 0.61.5) @@ -304,6 +355,8 @@ PODS: - UMSensorsInterface (5.1.0) - UMTaskManagerInterface (5.1.0) - Yoga (1.14.0) + - YogaKit (1.18.1): + - Yoga (~> 1.14) DEPENDENCIES: - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) @@ -316,6 +369,25 @@ DEPENDENCIES: - EXScreenOrientation (from `../node_modules/expo-screen-orientation/ios`) - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) - FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`) + - Flipper (~> 0.33.1) + - Flipper-DoubleConversion (= 1.1.7) + - Flipper-Folly (~> 2.1) + - Flipper-Glog (= 0.3.6) + - Flipper-PeerTalk (~> 0.0.4) + - Flipper-RSocket (~> 1.0) + - FlipperKit (~> 0.33.1) + - FlipperKit/Core (~> 0.33.1) + - FlipperKit/CppBridge (~> 0.33.1) + - FlipperKit/FBCxxFollyDynamicConvert (~> 0.33.1) + - FlipperKit/FBDefines (~> 0.33.1) + - FlipperKit/FKPortForwarding (~> 0.33.1) + - FlipperKit/FlipperKitHighlightOverlay (~> 0.33.1) + - FlipperKit/FlipperKitLayoutPlugin (~> 0.33.1) + - FlipperKit/FlipperKitLayoutTextSearchable (~> 0.33.1) + - FlipperKit/FlipperKitNetworkPlugin (~> 0.33.1) + - FlipperKit/FlipperKitReactPlugin (~> 0.33.1) + - FlipperKit/FlipperKitUserDefaultsPlugin (~> 0.33.1) + - FlipperKit/SKIOSNetworkPlugin (~> 0.33.1) - Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) @@ -374,8 +446,19 @@ DEPENDENCIES: SPEC REPOS: trunk: - boost-for-react-native + - CocoaAsyncSocket + - CocoaLibEvent + - Flipper + - Flipper-DoubleConversion + - Flipper-Folly + - Flipper-Glog + - Flipper-PeerTalk + - Flipper-RSocket + - FlipperKit + - OpenSSL-Universal - Sentry - Toast + - YogaKit EXTERNAL SOURCES: DoubleConversion: @@ -503,6 +586,8 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c + CocoaAsyncSocket: 694058e7c0ed05a9e217d1b3c7ded962f4180845 + CocoaLibEvent: 2fab71b8bd46dd33ddb959f7928ec5909f838e3f DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2 EXAppleAuthentication: 046c76335343eaa97f6ed8d35a9cf493a2c4d351 EXApplication: 7cf81de6fafccff42f5d1caa5c24a159db6b9437 @@ -513,8 +598,16 @@ SPEC CHECKSUMS: EXScreenOrientation: 44d3cd3a99a86b9cb681e742697bc2c057d7fbd2 FBLazyVector: aaeaf388755e4f29cd74acbc9e3b8da6d807c37f FBReactNativeSpec: 118d0d177724c2d67f08a59136eb29ef5943ec75 + Flipper: 6c1f484f9a88d30ab3e272800d53688439e50f69 + Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41 + Flipper-Folly: c12092ea368353b58e992843a990a3225d4533c3 + Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6 + Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9 + Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7 + FlipperKit: 6dc9b8f4ef60d9e5ded7f0264db299c91f18832e Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51 glog: 1f3da668190260b06b429bb211bfbee5cd790c28 + OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355 RCTRequired: b153add4da6e7dbc44aebf93f3cf4fcae392ddf1 RCTTypeSafety: 9aa1b91d7f9310fc6eadc3cf95126ffe818af320 React: b6a59ef847b2b40bb6e0180a97d0ca716969ac78 @@ -566,7 +659,8 @@ SPEC CHECKSUMS: UMSensorsInterface: 48941f70175e2975af1a9386c6d6cb16d8126805 UMTaskManagerInterface: cb890c79c63885504ddc0efd7a7d01481760aca2 Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b + YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: a17f480863448723f1b256597206709dfa50870c +PODFILE CHECKSUM: b31e45ca912ffe41b915cb3dbc892ca3049708b7 COCOAPODS: 1.9.1 diff --git a/ios/ZulipMobile.xcodeproj/project.pbxproj b/ios/ZulipMobile.xcodeproj/project.pbxproj index 7de1184cf66..90bd4f1d810 100644 --- a/ios/ZulipMobile.xcodeproj/project.pbxproj +++ b/ios/ZulipMobile.xcodeproj/project.pbxproj @@ -393,9 +393,13 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = ZulipMobile/ZulipMobile.entitlements; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = 66KHCWMEYB; + ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "FB_SONARKIT_ENABLED=1", + ); HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = ZulipMobile/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.3; @@ -492,6 +496,12 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ""; IPHONEOS_DEPLOYMENT_TARGET = 10.3; + LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)"; + LIBRARY_SEARCH_PATHS = ( + "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", + "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", + "\"$(inherited)\"", + ); MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = org.zulip.ZulipMobile; @@ -541,6 +551,12 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ""; IPHONEOS_DEPLOYMENT_TARGET = 10.3; + LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)"; + LIBRARY_SEARCH_PATHS = ( + "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", + "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", + "\"$(inherited)\"", + ); MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = org.zulip.ZulipMobile; SDKROOT = iphoneos; diff --git a/ios/ZulipMobile/AppDelegate.m b/ios/ZulipMobile/AppDelegate.m index 013c2232749..288a947a3d8 100644 --- a/ios/ZulipMobile/AppDelegate.m +++ b/ios/ZulipMobile/AppDelegate.m @@ -13,6 +13,25 @@ #import #import +#if DEBUG + #import + #import + #import + #import + #import + #import + + static void InitializeFlipper(UIApplication *application) { + FlipperClient *client = [FlipperClient sharedClient]; + SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; + [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; + [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; + [client addPlugin:[FlipperKitReactPlugin new]]; + [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; + [client start]; + } +#endif + @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions