Enable NDEBUG in production builds (#36194)

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

This change is the iOS equivalent of D43344120 (https://github.com/facebook/react-native/commit/8486e191a170d9eae4d1d628a7539dc9e3d13ea4), but for iOS.

## Changelog:
[iOS][Fixed] - Turn on NDEBUG when pods are installed for production.

Reviewed By: cortinico

Differential Revision: D43388881

fbshipit-source-id: 5c16d3d7b4265e4ee2f265a5f992cffee30f3887
This commit is contained in:
Riccardo Cipolleschi
2023-02-19 01:55:16 -08:00
committed by Facebook GitHub Bot
parent 1629b9f0a1
commit 421df9ffd5
3 changed files with 48 additions and 4 deletions
@@ -111,6 +111,42 @@ class NewArchitectureTests < Test::Unit::TestCase
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
end
def test_modifyFlagsForNewArch_whenOnNewArchAndIsRelease_updateFlags
# Arrange
first_xcconfig = prepare_xcconfig("First")
second_xcconfig = prepare_xcconfig("Second")
react_core_debug_config = prepare_CXX_Flags_build_configuration("Debug")
react_core_release_config = prepare_CXX_Flags_build_configuration("Release")
yoga_debug_config = prepare_CXX_Flags_build_configuration("Debug")
yoga_release_config = prepare_CXX_Flags_build_configuration("Release")
installer = prepare_installer_for_cpp_flags(
[ first_xcconfig, second_xcconfig ],
{
"React-Core" => [ react_core_debug_config, react_core_release_config ],
"Yoga" => [ yoga_debug_config, yoga_release_config ],
}
)
# Act
NewArchitectureHelper.modify_flags_for_new_architecture(installer, true, is_release: true)
# Assert
assert_equal(first_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
assert_equal(first_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(first_xcconfig.save_as_invocation, ["a/path/First.xcconfig"])
assert_equal(second_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
assert_equal(second_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(second_xcconfig.save_as_invocation, ["a/path/Second.xcconfig"])
assert_equal(react_core_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
assert_equal(react_core_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(react_core_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
assert_equal(react_core_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
end
# =================================== #
# Test - install Modules Dependencies #
# =================================== #
+11 -3
View File
@@ -38,15 +38,17 @@ class NewArchitectureHelper
end
end
def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: false)
unless is_new_arch_enabled
return
end
ndebug_flag = (is_release ? " -DNDEBUG" : "")
# 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'] = @@new_arch_cpp_flags
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags + ndebug_flag
config_file.attributes['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
xcconfig_path = aggregate_target.xcconfig_path(config_name)
config_file.save_as(xcconfig_path)
end
@@ -59,6 +61,12 @@ class NewArchitectureHelper
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags
end
end
target_installation_result.native_target.build_configurations.each do |config|
current_flags = config.build_settings['OTHER_CPLUSPLUSFLAGS'] != nil ? config.build_settings['OTHER_CPLUSPLUSFLAGS'] : ""
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = current_flags + ndebug_flag
config.build_settings['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
end
end
end
+1 -1
View File
@@ -218,7 +218,7 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == "1"
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: ENV['PRODUCTION'] == "1")
Pod::UI.puts "Pod install took #{Time.now.to_i - $START_TIME} [s] to run".green
end