Define RN_BUILDING for React Native's own CMake, SwiftPM, and Buck targets - #57861
Open
coado wants to merge 3 commits into
Open
Define RN_BUILDING for React Native's own CMake, SwiftPM, and Buck targets#57861coado wants to merge 3 commits into
coado wants to merge 3 commits into
Conversation
Summary: `install_modules_dependencies` is the helper every third-party New Architecture library calls from its own podspec, and `update_search_paths` covers the user project and the pod targets that don't go through it. Neither knew about `React-cxxstableapi`. React Native's public C++ headers are starting to include the shared guard header `<react/cxxstableapi/UmbrellaGuard.h>`. The include is unconditional, so a third-party pod that includes any guarded React Native header has to be able to resolve it. Today it can't: in the default static-library mode `$(PODS_ROOT)/Headers/Public/React-cxxstableapi` is missing from the search path, and under `use_frameworks!` the `React_cxxstableapi.framework/Headers` entry is missing. Declare the dependency and add the matching framework header search path in both places. Changelog: [iOS][Added] - Add a `React-cxxstableapi` dependency to third-party New Architecture pods so they can resolve React Native's C++ API guard headers Differential Revision: D110052811
Summary: React Native's public C++ headers are gaining guards from `react/cxxstableapi`. Those guards 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 fine-grained headers directly, so they have to be exempt — the guards recognise the exemption via `RN_BUILDING`. Mark every first-party pod as part of React Native's own build by defining `RN_BUILDING` for it, through a new `mark_as_react_native_build` helper called last in each spec block (it merges into `GCC_PREPROCESSOR_DEFINITIONS` as `pod_target_xcconfig` stands at call time, so a later assignment would drop it). Third-party pods deliberately do NOT get this: they compile their own code against the public API and must remain subject to the guards. For the same reason the definition goes into `pod_target_xcconfig`, which applies to the pod's own target, rather than `user_target_xcconfig`, which would leak it to the app. Not applied to `third-party-podspecs/`, `sdks/hermes-engine`, or the codegen podspec templates — those are third-party or app-side generated pods, and exempting them would be an enforcement hole rather than a no-op. This change is inert on its own: nothing behaves differently unless a consumer defines `RN_STRICT_API`. Changelog: [Internal] Differential Revision: D115051089
…rgets Summary: 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] Differential Revision: D115051088
|
@coado has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115051088. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
React Native's public C++ headers are gaining guards from
react/cxxstableapi, whichturn 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 includingthose headers directly, so they are exempted via
RN_BUILDING.Unlike CocoaPods, these three build systems each have a single chokepoint:
add_compile_definitions(RN_BUILDING)in the ReactAndroid JNI project,a directory property inherited by every
add_react_common_subdirbelow it. It isdeclared 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.
.definein the sharedTarget.reactNativeTargetfactory that everyReact Native target is created through.
cxxSettingsare per-target and are notinherited by packages that depend on React.
_set_rn_building_flaghelper called from the four macros React Native's owntargets use. It is
preprocessor_flags, deliberatelynot
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