You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 47f744d
Browse filesBrowse the repository at this point in the historyBrowse files
Add Swift Package Manager opt-ins for RN_STRICT_API and RN_ALLOW_FRAMEWORKS (#59043)
Summary:
Pull Request resolved: #59043
Let iOS apps that use the Swift Package Manager setup enforce React Native's C++ stable API, matching the CocoaPods and Android opt-ins. Two env vars are read by `npx react-native spm add` / `update`:
- `RN_STRICT_API=1` defines the `RN_STRICT_API` macro, which arms the `react/cxxstableapi` guards.
- `RN_ALLOW_FRAMEWORKS=1` defines the `RN_ALLOW_FRAMEWORKS` macro, which silences their "for frameworks" warning.
Each variable is named after the macro it defines, as in the CocoaPods opt-in.
Each opted-in macro is defined for the app's own code:
- the app target (`GCC_PREPROCESSOR_DEFINITIONS`, seeded with `$(inherited)`),
- the packages the autolinker generates for the app's local `spm.modules`,
- the app codegen package (`ReactCodegen`, `ReactAppDependencyProvider`).
Generated code never warns: the codegen package always defines `RN_ALLOW_FRAMEWORKS`, because nobody can act on a warning in generated code and libraries are held to the API in their own builds.
Under SwiftPM every library builds from its own `Package.swift`, so a library declares `RN_ALLOW_FRAMEWORKS` there, and the app's opt-ins do not reach libraries. React Native itself ships prebuilt, so none of its code is compiled with these macros.
The Xcode build phase runs `spm sync` without the shell environment, so `add`/`update` record the chosen macros in `.spm-injected.json` and every later sync regenerates the packages from that record. As with `pod install`, each `add`/`update` re-reads the variables: running `update` without one turns its macro off, and `deinit` removes the app-target defines along with the rest of the injection.
Changelog:
[iOS][Added] - Add `RN_STRICT_API` and `RN_ALLOW_FRAMEWORKS` opt-ins for the Swift Package Manager setup to enforce React Native's C++ stable API in the app's native code
Reviewed By: cipolleschi
Differential Revision: D124985657
fbshipit-source-id: 5ec66f94d5e3bb9e75fa305487cb39d2bd7e9d95
0 commit comments