Skip to content

Commit e34aa1c

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Cover react/nativemodule/core with Stable API guards (#58327)
Summary: Classifies `react/nativemodule/core:core` as a public target under the C++ stable API three-tier visibility model. Adds `#include <react/cxxstableapi/UmbrellaGuard.h>` to the module's 8 exported C++ headers and introduces the module umbrella `React/NativeModuleCore.h`, wiring the guard dependency into BUCK, CMake and CocoaPods and the umbrella into BUCK, CMake, CocoaPods, the iOS prebuild header config and the Android prefab export. Consumers that opt into `RN_STRICT_API` now get an error if they include the module's headers directly, and should include `<React/NativeModuleCore.h>` instead; without that flag the guards are inert, so no existing build changes behaviour. Changelog: [Internal] Differential Revision: D118801779
1 parent 25c5539 commit e34aa1c

13 files changed

Lines changed: 76 additions & 1 deletion

File tree

packages/react-native/ReactAndroid/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ val preparePrefab by
227227
Pair("../ReactCommon/jserrorhandler/", "jserrorhandler/"),
228228
Pair("../ReactCommon/react/bridging/", "react/bridging/"),
229229
Pair("../ReactCommon/react/nativemodule/core/", ""),
230+
Pair("../ReactCommon/react/nativemodule/core/React/", "React/"),
230231
Pair("../ReactCommon/react/nativemodule/core/platform/android/", ""),
231232
Pair(
232233
"../ReactCommon/react/renderer/componentregistry/",

packages/react-native/ReactCommon/ReactCommon.podspec

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,22 @@ Pod::Spec.new do |s|
5151

5252
ss.subspec "core" do |sss|
5353
sss.source_files = podspec_sources("react/nativemodule/core/ReactCommon/**/*.{cpp,h}", "react/nativemodule/core/ReactCommon/**/*.h")
54-
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_debug.framework/Headers\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_featureflags.framework/Headers\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-utils/React_utils.framework/Headers\"" }
54+
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_debug.framework/Headers\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_featureflags.framework/Headers\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-utils/React_utils.framework/Headers\"" }
5555
sss.dependency "React-bridging"
5656
sss.dependency "React-cxxreact", version
5757
sss.dependency "React-debug", version
5858
sss.dependency "React-featureflags", version
5959
sss.dependency "React-utils", version
6060
end
61+
62+
ss.subspec "coreUmbrella" do |sss|
63+
sss.source_files = "react/nativemodule/core/React/*.h"
64+
sss.header_dir = ""
65+
sss.header_mappings_dir = "react/nativemodule/core"
66+
end
6167
end
6268

69+
s.dependency "React-cxxstableapi"
70+
6371
mark_as_react_native_build(s)
6472
end

packages/react-native/ReactCommon/react/nativemodule/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ target_include_directories(react_nativemodule_core
2222
${CMAKE_CURRENT_SOURCE_DIR}
2323
${platform_DIR}
2424
)
25+
target_include_directories(react_nativemodule_core INTERFACE ${REACT_COMMON_DIR}/react/nativemodule/core)
2526

2627
react_native_android_selector(fbjni fbjni "")
2728
react_native_android_selector(reactnativejni reactnativejni "")
@@ -31,6 +32,7 @@ target_link_libraries(react_nativemodule_core
3132
glog
3233
jsi
3334
react_bridging
35+
react_cxxstableapi
3436
react_debug
3537
react_utils
3638
react_featureflags
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
// =============================================================================
11+
// Umbrella header for the `react/nativemodule/core` module - public entry
12+
// point.
13+
//
14+
// #include <React/NativeModuleCore.h>
15+
//
16+
// Re-exports the module's public interface headers. React Native's own code
17+
// should keep using the fine-grained `<ReactCommon/...>` includes; only outside
18+
// consumers use this umbrella.
19+
// =============================================================================
20+
21+
// Marks that the following headers are pulled in through the umbrella, so their
22+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
23+
// is saved and restored rather than defined and undefined: the scope ends at
24+
// this block, so later *direct* includes in the same TU are still caught, and
25+
// it nests inside an enclosing umbrella rather than disarming it.
26+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
27+
#undef RN_UMBRELLA_CONTEXT
28+
#define RN_UMBRELLA_CONTEXT 1
29+
30+
#include <ReactCommon/CxxTurboModuleUtils.h>
31+
#include <ReactCommon/TurboModule.h>
32+
#include <ReactCommon/TurboModuleBinding.h>
33+
#include <ReactCommon/TurboModulePerfLogger.h>
34+
#include <ReactCommon/TurboModuleUtils.h>
35+
#include <ReactCommon/TurboModuleWithJSIBindings.h>
36+
37+
#ifdef ANDROID
38+
#include <ReactCommon/JavaInteropTurboModule.h>
39+
#include <ReactCommon/JavaTurboModule.h>
40+
#endif
41+
42+
#undef RN_UMBRELLA_CONTEXT
43+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <react/cxxstableapi/UmbrellaGuard.h>
11+
1012
#include <ReactCommon/CallInvoker.h>
1113
#include <ReactCommon/TurboModule.h>
1214
#include <functional>

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <react/cxxstableapi/UmbrellaGuard.h>
11+
1012
#include <memory>
1113
#include <string>
1214
#include <unordered_map>

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <react/cxxstableapi/UmbrellaGuard.h>
11+
1012
#include <string>
1113

1214
#include <jsi/jsi.h>

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModulePerfLogger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <react/cxxstableapi/UmbrellaGuard.h>
11+
1012
#include <reactperflogger/NativeModulePerfLogger.h>
1113
#include <memory>
1214

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <react/cxxstableapi/UmbrellaGuard.h>
11+
1012
#include <jsi/jsi.h>
1113
#include <react/bridging/LongLivedObject.h>
1214
#include <cassert>

packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleWithJSIBindings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <react/cxxstableapi/UmbrellaGuard.h>
11+
1012
#include <ReactCommon/CallInvoker.h>
1113
#include <jsi/jsi.h>
1214

0 commit comments

Comments
 (0)