Skip to content

Commit 3b66079

Browse files
Dawid Małeckimeta-codesync[bot]
authored andcommitted
Define RN_BUILDING for React Native's own CMake, SwiftPM, and Buck targets
Summary: Companion to the CocoaPods change: does the same for the other three build systems, so every build has exactly one place that states "these targets are React Native's own". 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 — those build against the prefab artifacts through `ReactNative-application.cmake`. For that reason the flag deliberately does NOT go into `target_compile_reactnative_options`, which app and third-party module builds do call. - 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. These macros are also used by ~300 product packages that *consume* React Native, and those must stay subject to the guards, so the flag is scoped by package prefix rather than applied unconditionally. 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] Differential Revision: D115051088
1 parent a007a2e commit 3b66079

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
@@ -948,6 +948,10 @@ extension Target {
948948
CXXSetting.headerSearchPath(relativeSearchPath(numOfSlash + 1, ".build/headers/React")),
949949
]
950950

951+
// Every target built through this factory is React Native's own, so RN_BUILDING
952+
// keeps the react/cxxstableapi guards inert for internal sources. cxxSettings are
953+
// per-target and are not inherited by packages that depend on React, so this does
954+
// not exempt consumers from the guards.
951955
let cxxSettings =
952956
[
953957
.unsafeFlags(["-std=c++20"]),
@@ -956,6 +960,7 @@ extension Target {
956960
.define("USE_HERMES", to: "1"),
957961
.define("RCT_REMOVE_LEGACY_ARCH", to: "1"),
958962
.define("HERMES_V1_ENABLED", to: "1"),
963+
.define("RN_BUILDING", to: "1"),
959964
] + defines + cxxCommonHeaderPaths
960965

961966
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)