Automate setting the RCTNewArchEnabled flag (#49927)

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

This change automates updating App's Info.plist with the new `RCTNewArchEnabled` boolean entry. The value depends on how the pod install is set up. In this way, we maintain the previous UX to enable/disable the New Arch.

## Context
The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not.

However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example:

- New Arch / Hermes
- Old Arch / Hermes
- New Arch / JSC
- Old Arch / JSC
- ...

## Backward compatibility
We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself.

## Changelog:
[iOS][Added] -

Reviewed By: cortinico

Differential Revision: D70888212

fbshipit-source-id: 541a818e02ccb96c822de29b0714646d1e69a5a9
This commit is contained in:
Riccardo Cipolleschi
2025-03-11 05:05:49 -07:00
committed by Facebook GitHub Bot
parent 6dd721b258
commit 3b3d502ccf
2 changed files with 38 additions and 0 deletions
@@ -9,6 +9,7 @@ require_relative "./utils.rb"
require_relative "./helpers.rb"
require_relative "./jsengine.rb"
class NewArchitectureHelper
@@NewArchWarningEmitted = false # Used not to spam warnings to the user.
@@ -159,4 +160,40 @@ class NewArchitectureHelper
def self.new_arch_enabled
return ENV["RCT_NEW_ARCH_ENABLED"] == '0' ? false : true
end
def self.set_RCTNewArchEnabled_in_info_plist(installer, new_arch_enabled)
projectPaths = installer.aggregate_targets
.map{ |t| t.user_project }
.uniq{ |p| p.path }
.map{ |p| p.path }
excluded_info_plist = ["/Pods", "Tests", "metainternal", ".bundle"]
projectPaths.each do |projectPath|
projectFolderPath = File.dirname(projectPath)
infoPlistFiles = `find #{projectFolderPath} -name "Info.plist"`
infoPlistFiles = infoPlistFiles.split("\n").map { |f| f.strip }
infoPlistFiles.each do |infoPlistFile|
# If infoPlistFile contains Pods or tests, skip it
should_skip = false
excluded_info_plist.each do |excluded|
if infoPlistFile.include? excluded
should_skip = true
end
end
next if should_skip
# Read the file as a plist
info_plist = Xcodeproj::Plist.read_from_path(infoPlistFile)
# Check if it contains the RCTNewArchEnabled key
if info_plist["RCTNewArchEnabled"] and info_plist["RCTNewArchEnabled"] == new_arch_enabled
next
end
# Add the key and value to the plist
info_plist["RCTNewArchEnabled"] = new_arch_enabled ? true : false
Xcodeproj::Plist.write_to_path(info_plist, infoPlistFile)
end
end
end
end
@@ -451,6 +451,7 @@ def react_native_post_install(
NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
NewArchitectureHelper.modify_flags_for_new_architecture(installer, NewArchitectureHelper.new_arch_enabled)
NewArchitectureHelper.set_RCTNewArchEnabled_in_info_plist(installer, NewArchitectureHelper.new_arch_enabled)
if ENV['USE_HERMES'] == '0' && ENV['USE_THIRD_PARTY_JSC'] != '1'
print_jsc_removal_message()