From 090d671d34c516175781aae4d20a4a2644487c25 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Thu, 4 Dec 2025 06:36:52 -0800 Subject: [PATCH] Fix remaining missing debugger build flags for open source builds (#54774) Summary: NOTE: This diff is a backport of https://github.com/facebook/react-native/pull/54770, where on the `0.83-stable` release branch, Network support for React Native DevTools was in a broken state under the open source build systems. ### Cause Network debugging support depends a number of `REACT_NATIVE_DEBUGGER_ENABLED` preprocessor flags, which we use to compile away any overhead in production builds. As we unfortunately use a total of **4 native build systems** today (with Buck 2 internally and primarily), the registration of these flags was missing across a number of native ObjC/C++ packages, which are now fixed with this PR. - D87864636 aimed to address this as we weren't seeing the Network panel at all. However, it was insufficient, as it has only partially enabled network features between platforms. ### This diff Add missing preprocessor flags in: - Android: - `src/main/jni/react/devsupport/CMakeLists.txt` - `src/main/jni/CMakeLists.txt` - iOS (Pods): - `React-jsinspectorNetwork` - iOS (`Package.swift`): - `Libraries/Network` Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D88284345 --- packages/react-native/Package.swift | 6 +++++- .../react-native/ReactAndroid/src/main/jni/CMakeLists.txt | 7 +++++++ .../src/main/jni/react/devsupport/CMakeLists.txt | 7 +++++++ packages/react-native/scripts/cocoapods/utils.rb | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Package.swift b/packages/react-native/Package.swift index d95d1c6a1d3c..8653c0505251 100644 --- a/packages/react-native/Package.swift +++ b/packages/react-native/Package.swift @@ -593,7 +593,11 @@ let reactRCTBlob = RNTarget( let reactRCTNetwork = RNTarget( name: .reactRCTNetwork, path: "Libraries/Network", - dependencies: [.yoga, .jsi, .reactTurboModuleCore] + dependencies: [.yoga, .jsi, .reactTurboModuleCore], + defines: [ + CXXSetting.define("REACT_NATIVE_DEBUGGER_ENABLED", to: "1", .when(configuration: BuildConfiguration.debug)), + CXXSetting.define("REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY", to: "1", .when(configuration: BuildConfiguration.debug)), + ] ) /// React-RCTVibration.podspec diff --git a/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt index 0e7e429d2c0e..dc7447d202c8 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt +++ b/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt @@ -338,3 +338,10 @@ target_include_directories(reactnative $ $ ) + +if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED) + target_compile_options(reactnative PRIVATE + -DREACT_NATIVE_DEBUGGER_ENABLED=1 + -DREACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1 + ) +endif () diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/CMakeLists.txt index 3905a4af4ad1..b1a528edf8d2 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/CMakeLists.txt +++ b/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/CMakeLists.txt @@ -23,3 +23,10 @@ target_link_libraries(react_devsupportjni react_networking) target_compile_reactnative_options(react_devsupportjni PRIVATE) + +if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED) + target_compile_options(react_devsupportjni PRIVATE + -DREACT_NATIVE_DEBUGGER_ENABLED=1 + -DREACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1 + ) +endif () diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index d87c0e22d51d..a24489637f28 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -58,9 +58,11 @@ def self.set_gcc_preprocessor_definition_for_React_hermes(installer) def self.set_gcc_preprocessor_definition_for_debugger(installer) self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED=1", "React-jsinspector", :debug) + self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED=1", "React-jsinspectornetwork", :debug) self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED=1", "React-RCTNetwork", :debug) self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED=1", "React-networking", :debug) self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1", "React-jsinspector", :debug) + self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1", "React-jsinspectornetwork", :debug) self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1", "React-RCTNetwork", :debug) self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1", "React-networking", :debug) end