Skip to content

Commit a9df3d5

Browse files
coadometa-codesync[bot]
authored andcommitted
Define RN_BUILDING for React Native's own CMake, SwiftPM, and Buck targets (#57861)
Summary: Pull Request resolved: #57861 React Native's public C++ headers are gaining guards from `react/cxxstableapi`, which turn a direct include of a fine-grained header into an error for consumers that opt into the strict API by defining `RN_STRICT_API`. React Native's own sources keep including those headers directly, so they are exempted via `RN_BUILDING`. Unlike CocoaPods, these three build systems each have a single chokepoint: - CMake: one `add_compile_definitions(RN_BUILDING)` in the ReactAndroid JNI project, a directory property inherited by every `add_react_common_subdir` below it. It is declared *after* the third-party NDK subdirectories so glog/boost/folly/fmt never see it, and this project never compiles app or third-party module code. - SwiftPM: one `.define` in the shared `Target.reactNativeTarget` factory that every React Native target is created through. `cxxSettings` are per-target and are not inherited by packages that depend on React. - Buck: a `_set_rn_building_flag` helper called from the four macros React Native's own targets use. It is `preprocessor_flags`, deliberately not `exported_preprocessor_flags`, so dependents are not exempted either. This change is inert on its own: nothing behaves differently unless a consumer defines `RN_STRICT_API`. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D115051088 fbshipit-source-id: 70b525a7291227a4400beefdba2b0a3571dc032c
1 parent 2e4e830 commit a9df3d5

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

packages/react-native/Package.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ extension Target {
959959
(REMOVE_LEGACY_MODULE_INTEROP ? [.define("RCT_REMOVE_LEGACY_MODULE_INTEROP", to: "1")] : [])
960960
+ (REMOVE_LEGACY_COMPONENT_INTEROP ? [.define("RCT_REMOVE_LEGACY_COMPONENT_INTEROP", to: "1")] : [])
961961

962+
// Every target built through this factory is React Native's own, so RN_BUILDING
963+
// keeps the react/cxxstableapi guards inert for internal sources. cxxSettings are
964+
// per-target and are not inherited by packages that depend on React, so this does
965+
// not exempt consumers from the guards.
962966
let cxxSettings =
963967
[
964968
.unsafeFlags(["-std=c++20"]),
@@ -967,6 +971,7 @@ extension Target {
967971
.define("USE_HERMES", to: "1"),
968972
.define("RCT_REMOVE_LEGACY_ARCH", to: "1"),
969973
.define("HERMES_V1_ENABLED", to: "1"),
974+
.define("RN_BUILDING", to: "1"),
970975
] + legacyInteropDefines + defines + cxxCommonHeaderPaths
971976

972977
return .target(

packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ add_react_third_party_ndk_subdir(fast_float)
5858
add_react_third_party_ndk_subdir(fmt)
5959
add_react_third_party_ndk_subdir(folly)
6060

61+
# Marks everything added below as React Native's own build, so the
62+
# react/cxxstableapi guards let internal sources keep including the
63+
# fine-grained headers they fence off from consumers. Deliberately declared
64+
# after the third-party subdirectories so it never reaches them, and this
65+
# project never compiles app or third-party module code (those build against
66+
# the prefab artifacts through ReactNative-application.cmake).
67+
add_compile_definitions(RN_BUILDING)
68+
6169
# Common targets
6270
add_react_common_subdir(yoga)
6371
add_react_common_subdir(runtimeexecutor)

0 commit comments

Comments
 (0)