diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 6768fdb01be..4a2c9644d6d 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -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) diff --git a/template/ios/HelloWorld.xcodeproj/project.pbxproj b/template/ios/HelloWorld.xcodeproj/project.pbxproj index b383416d524..7dfdffdd84e 100644 --- a/template/ios/HelloWorld.xcodeproj/project.pbxproj +++ b/template/ios/HelloWorld.xcodeproj/project.pbxproj @@ -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; diff --git a/template/ios/Podfile b/template/ios/Podfile index 9409747f917..403f9313294 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -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