Skip to content

Add Swift Package Manager opt-in for RN_STRICT_API - #59043

Open
coado wants to merge 1 commit into
react:mainfrom
coado:export-D124985657
Open

coado wants to merge 1 commit into
react:mainfrom
coado:export-D124985657

Conversation

@coado

@coado coado commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Summary:
Let iOS apps that use the Swift Package Manager setup enforce React Native's C++ stable API, matching the CocoaPods and Android opt-ins. Setting RCT_STRICT_CXX_API=1 when running npx react-native spm add or update defines RN_STRICT_API in:

  • the app target (GCC_PREPROCESSOR_DEFINITIONS, seeded with $(inherited)),
  • every package the autolinker generates (inline spm.modules targets and the synthesized per-dependency packages),
  • the app codegen package (ReactCodegen, ReactAppDependencyProvider).

React Native itself ships prebuilt in this setup, so none of its code is compiled with the flag.

The Xcode build phase runs spm sync without the shell environment, so add/update record the choice in .spm-injected.json and every later sync regenerates the packages from that record. As with pod install, each add/update re-reads the variable: running update without it turns enforcement off, and deinit removes the app-target define along with the rest of the injection.

Libraries that ship their own Package.swift, upstream or created with spm scaffold, are referenced as-is and keep their own settings.

Changelog:
[iOS][Added] - Add RCT_STRICT_CXX_API opt-in for the Swift Package Manager setup to enforce React Native's C++ stable API in app and library native code

Differential Revision: D124985657

Summary:
Let iOS apps that use the Swift Package Manager setup enforce React Native's C++ stable API, matching the CocoaPods and Android opt-ins. Setting `RCT_STRICT_CXX_API=1` when running `npx react-native spm add` or `update` defines `RN_STRICT_API` in:

- the app target (`GCC_PREPROCESSOR_DEFINITIONS`, seeded with `$(inherited)`),
- every package the autolinker generates (inline `spm.modules` targets and the synthesized per-dependency packages),
- the app codegen package (`ReactCodegen`, `ReactAppDependencyProvider`).

React Native itself ships prebuilt in this setup, so none of its code is compiled with the flag.

The Xcode build phase runs `spm sync` without the shell environment, so `add`/`update` record the choice in `.spm-injected.json` and every later sync regenerates the packages from that record. As with `pod install`, each `add`/`update` re-reads the variable: running `update` without it turns enforcement off, and `deinit` removes the app-target define along with the rest of the injection.

Libraries that ship their own `Package.swift`, upstream or created with `spm scaffold`, are referenced as-is and keep their own settings.

Changelog:
[iOS][Added] - Add `RCT_STRICT_CXX_API` opt-in for the Swift Package Manager setup to enforce React Native's C++ stable API in app and library native code

Differential Revision: D124985657
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 13, 2026
@facebook-github-tools facebook-github-tools Bot added p: Software Mansion Partner: Software Mansion Partner labels Oct 13, 2026
@meta-codesync

meta-codesync Bot commented Oct 13, 2026

Copy link
Copy Markdown

@coado has exported this pull request. If you are a Meta employee, you can view the originating Diff in D124985657.

@facebook-github-tools facebook-github-tools Bot added the p: Facebook Partner: Facebook label Oct 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook p: Software Mansion Partner: Software Mansion Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant