Add Other C++ flags when RCT_NEW_ARCH_ENABLE=1 (#32777)

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

Changelog: [iOS][Added] Added the new architecture support to the new app template. To apply this change to your project, you will need to update your Podfile.  You can try it by using "RCT_NEW_ARCH_ENABLE=1 pod instal" command which updates necessary C++ flags and enable the new codegen discovery required for the new architecture. As context, We've modified the iOS template to have code required to enable the new architecture (aka Turbo modules and fabric / renderer) which requires updating AppDelegate. We also added the support in RNTester as well. We will be sharing more documentation about the new architecture.

Reviewed By: dmitryrykun

Differential Revision: D33154825

fbshipit-source-id: a46b98308e9d29780b6a5245e8faa8be1e257802
This commit is contained in:
Sota Ogo
2021-12-16 23:41:42 -08:00
committed by Facebook GitHub Bot
parent 51fe19084f
commit e330eee9c8
3 changed files with 60 additions and 5 deletions
+51
View File
@@ -11,6 +11,8 @@ $CODEGEN_COMPONENT_DIR = 'react/renderer/components'
$CODEGEN_MODULE_DIR = '.'
$REACT_CODEGEN_PODSPEC_GENERATED = false
$REACT_CODEGEN_DISCOVERY_DONE = false
DEFAULT_OTHER_CPLUSPLUSFLAGS = '$(inherited)'
NEW_ARCH_OTHER_CPLUSPLUSFLAGS = '$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
def use_react_native! (options={})
# The prefix to react-native
@@ -25,6 +27,12 @@ def use_react_native! (options={})
# Include Hermes dependencies
hermes_enabled = options[:hermes_enabled] ||= false
# Codegen Discovery is required when enabling new architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
Pod::UI.puts 'Setting USE_CODEGEN_DISCOVERY=1'
ENV['USE_CODEGEN_DISCOVERY'] = '1'
end
if `/usr/sbin/sysctl -n hw.optional.arm64 2>&1`.to_i == 1 && !RUBY_PLATFORM.include?('arm64')
Pod::UI.warn 'Do not use "pod install" from inside Rosetta2 (x86_64 emulation on arm64).'
Pod::UI.warn ' - Emulated x86_64 is slower than native arm64'
@@ -106,6 +114,20 @@ def use_react_native! (options={})
end
end
def get_default_flags()
flags = {
:fabric_enabled => false,
:hermes_enabled => false,
}
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
flags[:fabric_enabled] = true
flags[:hermes_enabled] = true
end
return flags
end
def use_flipper!(versions = {}, configurations: ['Debug'])
versions['Flipper'] ||= '0.99.0'
versions['Flipper-Boost-iOSX'] ||= '1.76.0.1.11'
@@ -217,6 +239,35 @@ def react_native_post_install(installer)
exclude_architectures(installer)
fix_library_search_paths(installer)
cpp_flags = DEFAULT_OTHER_CPLUSPLUSFLAGS
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
cpp_flags = NEW_ARCH_OTHER_CPLUSPLUSFLAGS
end
modify_flags_for_new_architecture(installer, cpp_flags)
end
def modify_flags_for_new_architecture(installer, cpp_flags)
# Add RCT_NEW_ARCH_ENABLED to Target pods xcconfig
installer.aggregate_targets.each do |aggregate_target|
aggregate_target.xcconfigs.each do |config_name, config_file|
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = cpp_flags
xcconfig_path = aggregate_target.xcconfig_path(config_name)
Pod::UI.puts xcconfig_path
config_file.save_as(xcconfig_path)
end
end
# Add RCT_NEW_ARCH_ENABLED to Pods project xcconfig
installer.pods_project.targets.each do |target|
# if target.name == 'React-Core'
if target.name == 'React-Core'
puts "#{target.name}"
target.build_configurations.each do |config|
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = cpp_flags
end
end
end
end
def build_codegen!(react_native_path)
@@ -482,7 +482,6 @@
baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-HelloWorld.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
ENABLE_BITCODE = NO;
@@ -509,7 +508,6 @@
baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-HelloWorld.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_FILE = HelloWorld/Info.plist;
@@ -534,7 +532,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
@@ -605,7 +603,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
+7 -1
View File
@@ -6,10 +6,16 @@ platform :ios, '11.0'
target 'HelloWorld' do
config = use_native_modules!
# Flags change depending on the env values.
flags = get_default_flags()
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
:hermes_enabled => flags[:hermes_enabled],
:fabric_enabled => flags[:fabric_enabled],
# An abosolute path to your application root.
:app_path => "#{Dir.pwd}/.."
)
target 'HelloWorldTests' do