Skip to content

Commit

Permalink
Enable NDEBUG in production builds (#36194)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Feb 19, 2023
1 parent 1629b9f commit 421df9f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
36 changes: 36 additions & 0 deletions scripts/cocoapods/__tests__/new_architecture-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ def test_modifyFlagsForNewArch_whenOnNewArch_updateFlags
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 #
# =================================== #
Expand Down
14 changes: 11 additions & 3 deletions scripts/cocoapods/new_architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ def self.set_clang_cxx_language_standard_if_needed(installer)
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
Expand All @@ -59,6 +61,12 @@ def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
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

Expand Down
2 changes: 1 addition & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 421df9f

Please sign in to comment.