Skip to content

Commit 421df9f

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Enable NDEBUG in production builds (#36194)
Summary: Pull Request resolved: #36194 This change is the iOS equivalent of D43344120 (8486e19), 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
1 parent 1629b9f commit 421df9f

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

scripts/cocoapods/__tests__/new_architecture-test.rb

+36
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,42 @@ def test_modifyFlagsForNewArch_whenOnNewArch_updateFlags
111111
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
112112
end
113113

114+
def test_modifyFlagsForNewArch_whenOnNewArchAndIsRelease_updateFlags
115+
# Arrange
116+
first_xcconfig = prepare_xcconfig("First")
117+
second_xcconfig = prepare_xcconfig("Second")
118+
react_core_debug_config = prepare_CXX_Flags_build_configuration("Debug")
119+
react_core_release_config = prepare_CXX_Flags_build_configuration("Release")
120+
yoga_debug_config = prepare_CXX_Flags_build_configuration("Debug")
121+
yoga_release_config = prepare_CXX_Flags_build_configuration("Release")
122+
123+
installer = prepare_installer_for_cpp_flags(
124+
[ first_xcconfig, second_xcconfig ],
125+
{
126+
"React-Core" => [ react_core_debug_config, react_core_release_config ],
127+
"Yoga" => [ yoga_debug_config, yoga_release_config ],
128+
}
129+
)
130+
# Act
131+
NewArchitectureHelper.modify_flags_for_new_architecture(installer, true, is_release: true)
132+
133+
# Assert
134+
assert_equal(first_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
135+
assert_equal(first_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
136+
assert_equal(first_xcconfig.save_as_invocation, ["a/path/First.xcconfig"])
137+
assert_equal(second_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
138+
assert_equal(second_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
139+
assert_equal(second_xcconfig.save_as_invocation, ["a/path/Second.xcconfig"])
140+
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")
141+
assert_equal(react_core_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
142+
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")
143+
assert_equal(react_core_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
144+
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
145+
assert_equal(yoga_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
146+
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
147+
assert_equal(yoga_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
148+
end
149+
114150
# =================================== #
115151
# Test - install Modules Dependencies #
116152
# =================================== #

scripts/cocoapods/new_architecture.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ def self.set_clang_cxx_language_standard_if_needed(installer)
3838
end
3939
end
4040

41-
def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
41+
def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: false)
4242
unless is_new_arch_enabled
4343
return
4444
end
45-
45+
ndebug_flag = (is_release ? " -DNDEBUG" : "")
4646
# Add RCT_NEW_ARCH_ENABLED to Target pods xcconfig
4747
installer.aggregate_targets.each do |aggregate_target|
4848
aggregate_target.xcconfigs.each do |config_name, config_file|
49-
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags
49+
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags + ndebug_flag
50+
config_file.attributes['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
51+
5052
xcconfig_path = aggregate_target.xcconfig_path(config_name)
5153
config_file.save_as(xcconfig_path)
5254
end
@@ -59,6 +61,12 @@ def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
5961
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags
6062
end
6163
end
64+
65+
target_installation_result.native_target.build_configurations.each do |config|
66+
current_flags = config.build_settings['OTHER_CPLUSPLUSFLAGS'] != nil ? config.build_settings['OTHER_CPLUSPLUSFLAGS'] : ""
67+
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = current_flags + ndebug_flag
68+
config.build_settings['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
69+
end
6270
end
6371
end
6472

scripts/react_native_pods.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
218218

219219
NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
220220
is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == "1"
221-
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
221+
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: ENV['PRODUCTION'] == "1")
222222

223223
Pod::UI.puts "Pod install took #{Time.now.to_i - $START_TIME} [s] to run".green
224224
end

0 commit comments

Comments
 (0)