Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Entirely control Flipper being enabled through Podfile (#1086)
Browse files Browse the repository at this point in the history
Summary:
Currently user’s are being told to add a definition of the `FB_SONARKIT_ENABLED` macro and examples, including those in stock React Native templates, set this for the user by making use of a `post_install` hook in the user’s `Podfile`. This leads to confusion, fragile code [when a user’s project dir structure deviates from vanilla], and is ultimately not necessary as CocoaPods already has dedicated mechanisms to:

* specify build settings (through the `xcconfig` property);
* and selectively include certain pods only in certain build configurations (e.g. debug).

Finally, this PR also includes a commit [to fix the current builds](https://github.com/facebook/flipper/pull/1086/files#r418526812).

## Changelog

> Entirely control Flipper being enabled through inclusion in Podfile and optionally limiting to certain build configurations using the `:configuration` directive.
Pull Request resolved: #1086

Test Plan: I have built and ran the Sample application, as well as used this version of Flipper with a new RN app built from `master`.

Reviewed By: passy

Differential Revision: D21381828

Pulled By: priteshrnandgaonkar

fbshipit-source-id: edf6dae28eb02336a49e8230654d6186360ea8d6
  • Loading branch information
alloy authored and facebook-github-bot committed May 5, 2020
1 parent 63a512a commit c393ee9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 316 deletions.
4 changes: 3 additions & 1 deletion FlipperKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Pod::Spec.new do |spec|
"ONLY_ACTIVE_ARCH": "YES",
"DEFINES_MODULE" => "YES",
"HEADER_SEARCH_PATHS" => header_search_paths }
ss.xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => "FB_SONARKIT_ENABLED=1", "OTHER_SWIFT_FLAGS" => "-Xcc -DFB_SONARKIT_ENABLED=1" }
end

spec.subspec 'FlipperKitHighlightOverlay' do |ss|
Expand Down Expand Up @@ -128,7 +129,8 @@ Pod::Spec.new do |spec|
spec.subspec "FlipperKitLayoutComponentKitSupport" do |ss|
ss.header_dir = "FlipperKitLayoutComponentKitSupport"
ss.dependency 'FlipperKit/Core'
ss.dependency 'ComponentKit', '~> 0.0'
ss.dependency 'ComponentKit', '~> 0.30'
ss.dependency 'RenderCore', '~> 0.30'
ss.dependency 'FlipperKit/FlipperKitLayoutPlugin'
ss.dependency 'FlipperKit/FlipperKitLayoutTextSearchable'
ss.dependency 'FlipperKit/FlipperKitHighlightOverlay'
Expand Down
136 changes: 27 additions & 109 deletions docs/getting-started/ios-native.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,49 @@ title: Set up your iOS app
sidebar_label: iOS
---

We support both Swift and Objective-C for Flipper with CocoaPods as build and distribution mechanism.
We support both Swift and Objective-C for Flipper with CocoaPods as build and distribution mechanism.

## CocoaPods

The following configuration assumed CocoaPods 1.9+.

<!--DOCUSAURUS_CODE_TABS-->
<!--Objective-C-->

```ruby
project 'MyApp.xcodeproj'
flipperkit_version = '0.40.0'

target 'MyApp' do
platform :ios, '9.0'
# use_framework!
pod 'FlipperKit', '~>' + flipperkit_version
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version

# If you use `use_frameworks!` in your Podfile,
# uncomment the below $static_framework array and also
# the pre_install section. This will cause Flipper and
# it's dependencies to be built as a static library and all other pods to
# be dynamic.
# $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
# 'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
# 'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
# 'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native']
#
# pre_install do |installer|
# Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
# installer.pod_targets.each do |pod|
# if $static_framework.include?(pod.name)
# def pod.build_type;
# Pod::BuildType.static_library
# end
# end
# end
# end

# This post_install hook adds the -DFB_SONARKIT_ENABLED=1 flag to OTHER_CFLAGS, necessary to expose Flipper classes in the header files
post_install do |installer|
file_name = Dir.glob("*.xcodeproj")[0]
app_project = Xcodeproj::Project.open(file_name)
app_project.native_targets.each do |target|
target.build_configurations.each do |config|
cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
cflags << '-DFB_SONARKIT_ENABLED=1'
end
config.build_settings['OTHER_CFLAGS'] = cflags
end
app_project.save
end
installer.pods_project.save
end
end
```

<!--Swift-->

```ruby
project 'MyApp.xcodeproj'
flipperkit_version = '0.40.0'

target 'MyApp' do
platform :ios, '9.0'

pod 'FlipperKit', '~>' + flipperkit_version
# Layout and network plugins are not yet supported for swift projects
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version
# It is likely that you'll only want to include Flipper in debug builds,
# in which case you add the `:configuration` directive:
pod 'FlipperKit', '~>' + flipperkit_version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version, :configuration => 'Debug'
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
# ...unfortunately at this time that means you'll need to explicitly mark
# transitive dependencies as being for debug build only as well:
pod 'Flipper-DoubleConversion', :configuration => 'Debug'
pod 'Flipper-Folly', :configuration => 'Debug'
pod 'Flipper-Glog', :configuration => 'Debug'
pod 'Flipper-PeerTalk', :configuration => 'Debug'
pod 'CocoaLibEvent', :configuration => 'Debug'
pod 'boost-for-react-native', :configuration => 'Debug'
pod 'OpenSSL-Universal', :configuration => 'Debug'
pod 'CocoaAsyncSocket', :configuration => 'Debug'
# ...except, of course, those transitive dependencies that your
# application itself depends, e.g.:
pod 'ComponentKit', '~> 0.30'

# If you use `use_frameworks!` in your Podfile,
# uncomment the below $static_framework array and also
# the pre_install section. This will cause Flipper and
# it's dependencies to be built as a static library and all other pods to
# be dynamic.
#
# NOTE Doing this may lead to a broken build if any of these are also
# transitive dependencies of other dependencies and are expected
# to be built as frameworks.
#
# $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
# 'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
# 'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
Expand All @@ -101,52 +62,9 @@ target 'MyApp' do
# end
# end
# end


# This post_install hook adds the -DFB_SONARKIT_ENABLED flag to OTHER_SWIFT_FLAGS, necessary to build swift target
post_install do |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
file_name = Dir.glob("*.xcodeproj")[0]
app_project = Xcodeproj::Project.open(file_name)
app_project.native_targets.each do |target|
target.build_configurations.each do |config|
if (config.build_settings['OTHER_SWIFT_FLAGS'])
unless config.build_settings['OTHER_SWIFT_FLAGS'].include? '-DFB_SONARKIT_ENABLED'
puts 'Adding -DFB_SONARKIT_ENABLED ...'
swift_flags = config.build_settings['OTHER_SWIFT_FLAGS']
if swift_flags.split.last != '-Xcc'
config.build_settings['OTHER_SWIFT_FLAGS'] << ' -Xcc'
end
config.build_settings['OTHER_SWIFT_FLAGS'] << ' -DFB_SONARKIT_ENABLED'
end
else
puts 'OTHER_SWIFT_FLAGS does not exist thus assigning it to `$(inherited) -Xcc -DFB_SONARKIT_ENABLED`'
config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -Xcc -DFB_SONARKIT_ENABLED'
end
app_project.save
end
end
installer.pods_project.save
end
end
```

<!--END_DOCUSAURUS_CODE_TABS-->

You need to compile your project with the `FB_SONARKIT_ENABLED=1` compiler flag. The above `post_install` hook adds this compiler flag to your project settings.

<div class="warning">

On the first run of `pod install`, `FB_SONARKIT_ENABLED=1` may not be added in the "Build Settings" of your project, but in all the subsequent runs of `pod install`, the above `post_install` hook successfully adds the compiler flag. So before running your app, make sure that `FB_SONARKIT_ENABLED=1` is present in `OTHER_CFLAGS` and `OTHER_SWIFT_FLAGS` for Objective-C and Swift projects respectively.

</div>

## For pure Objective-C projects

For pure Objective-C projects, add the following things in your settings:
Expand All @@ -156,13 +74,13 @@ For pure Objective-C projects, add the following things in your settings:

```
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
```

3. If after the above two steps there are still error's like `Undefined symbol _swift_getFunctionReplacement` then set `DEAD_CODE_STRIPPING` to `YES`. Reference for this fix is [here](https://forums.swift.org/t/undefined-symbol-swift-getfunctionreplacement/30495/4)

This is done to overcome a bug with Xcode 11 which fails to compile swift code when bitcode is enabled. Flipper transitively depends on YogaKit which is written in Swift. More about this issue can be found [here](https://twitter.com/krzyzanowskim/status/1151549874653081601?s=21) and [here](https://github.com/Carthage/Carthage/issues/2825).


Install the dependencies by running `pod install`. You can now import and initialize Flipper in your
AppDelegate.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <ComponentKit/CKComponentLayout.h>
#import <ComponentKit/CKFlexboxComponent.h>
#import <ComponentKit/CKOptional.h>
#import <ComponentKit/CKVariant.h>
#import <RenderCore/CKVariant.h>

#import <vector>

Expand Down
62 changes: 17 additions & 45 deletions iOS/Sample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,22 @@ source 'https://github.com/CocoaPods/Specs'

target 'Sample' do
platform :ios, '9.0'
pod 'FlipperKit', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/SKIOSNetworkPlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitReactPlugin', :path => '../../FlipperKit.podspec'
pod 'Flipper', :path => '../../Flipper.podspec'

# If you use `use_frameworks!` in your Podfile,
# uncomment the below $static_framework array and also
# the pre_install section. This will cause Flipper and
# it's dependencies to be built as a static library and all other pods to
# be dynamic.
# $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
# 'CocoaAsyncSocket', 'ComponentKit', 'DoubleConversion',
# 'glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
# 'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native']
#
# pre_install do |installer|
# Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
# installer.pod_targets.each do |pod|
# if $static_framework.include?(pod.name)
# def pod.build_type;
# Pod::Target::BuildType.static_library
# end
# end
# end
# end

# It also adds -DFB_SONARKIT_ENABLED=1 flag to OTHER_CFLAGS, necessary to build expose Flipper classes in the header files
post_install do |installer|
file_name = Dir.glob("*.xcodeproj")[0]
app_project = Xcodeproj::Project.open(file_name)
app_project.native_targets.each do |target|
target.build_configurations.each do |config|
cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
cflags << '-DFB_SONARKIT_ENABLED=1'
end
config.build_settings['OTHER_CFLAGS'] = cflags
end
app_project.save
end
installer.pods_project.save
end
# See docs/getting-started/ios-native.mdx
pod 'FlipperKit', :path => '../../FlipperKit.podspec', :configuration => 'Debug'
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', :path => '../../FlipperKit.podspec', :configuration => 'Debug'
pod 'FlipperKit/SKIOSNetworkPlugin', :path => '../../FlipperKit.podspec', :configuration => 'Debug'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec', :configuration => 'Debug'
pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec', :configuration => 'Debug'
pod 'FlipperKit/FlipperKitReactPlugin', :path => '../../FlipperKit.podspec', :configuration => 'Debug'
pod 'Flipper', :path => '../../Flipper.podspec', :configuration => 'Debug'
pod 'Flipper-DoubleConversion', :configuration => 'Debug'
pod 'Flipper-Folly', :configuration => 'Debug'
pod 'Flipper-Glog', :configuration => 'Debug'
pod 'Flipper-PeerTalk', :configuration => 'Debug'
pod 'CocoaLibEvent', :configuration => 'Debug'
pod 'boost-for-react-native', :configuration => 'Debug'
pod 'OpenSSL-Universal', :configuration => 'Debug'
pod 'CocoaAsyncSocket', :configuration => 'Debug'
pod 'ComponentKit', '~> 0.30'
end
76 changes: 0 additions & 76 deletions iOS/Sample/Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,12 @@
isa = XCBuildConfiguration;
baseConfigurationReference = BDF8FF7C018FDB3437209993 /* Pods-Sample.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"COCOAPODS=1",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_ROOT}/Headers/Public\"",
Expand All @@ -368,41 +363,6 @@
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
);
OTHER_CFLAGS = (
"$(inherited)",
"-fmodule-map-file=\"${PODS_ROOT}/Headers/Public/FlipperKit/FlipperKit.modulemap\"",
"-fmodule-map-file=\"${PODS_ROOT}/Headers/Public/yoga/Yoga.modulemap\"",
"-fmodule-map-file=\"${PODS_CONFIGURATION_BUILD_DIR}/YogaKit/YogaKit.modulemap\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/CocoaAsyncSocket\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/CocoaLibEvent\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/ComponentKit\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/DoubleConversion\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/Flipper\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/FlipperKit\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/Folly\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/OpenSSL-Static\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/PeerTalk\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/RSocket\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/Yoga\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/YogaKit\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/glog\"",
"-DFB_SONARKIT_ENABLED=1",
);
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-Wno-implicit-retain-self",
Expand Down Expand Up @@ -435,7 +395,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 081A9FC23643CD21C7D61AA1 /* Pods-Sample.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
Expand Down Expand Up @@ -468,41 +427,6 @@
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
);
OTHER_CFLAGS = (
"$(inherited)",
"-fmodule-map-file=\"${PODS_ROOT}/Headers/Public/FlipperKit/FlipperKit.modulemap\"",
"-fmodule-map-file=\"${PODS_ROOT}/Headers/Public/yoga/Yoga.modulemap\"",
"-fmodule-map-file=\"${PODS_CONFIGURATION_BUILD_DIR}/YogaKit/YogaKit.modulemap\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/CocoaAsyncSocket\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/CocoaLibEvent\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/ComponentKit\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/DoubleConversion\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/Flipper\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/FlipperKit\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/Folly\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/OpenSSL-Static\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/PeerTalk\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/RSocket\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/Yoga\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/YogaKit\"",
"-isystem",
"\"${PODS_ROOT}/Headers/Public/glog\"",
"-DFB_SONARKIT_ENABLED=1",
);
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-Wno-implicit-retain-self",
Expand Down
Loading

0 comments on commit c393ee9

Please sign in to comment.