Skip to content

Propagate RCT_REMOVE_LEGACY_ARCH to SWIFT_ACTIVE_COMPILATION_CONDITIONS#56974

Open
christophpurrer wants to merge 1 commit into
facebook:mainfrom
christophpurrer:export-D106466169
Open

Propagate RCT_REMOVE_LEGACY_ARCH to SWIFT_ACTIVE_COMPILATION_CONDITIONS#56974
christophpurrer wants to merge 1 commit into
facebook:mainfrom
christophpurrer:export-D106466169

Conversation

@christophpurrer
Copy link
Copy Markdown
Contributor

Summary:
Mirrors the existing C/C++ -DRCT_REMOVE_LEGACY_ARCH=1 flag into Swift's SWIFT_ACTIVE_COMPILATION_CONDITIONS so Swift sources (notably user AppDelegate.swift files derived from the community template) can branch on #if !RCT_REMOVE_LEGACY_ARCH.

Until now, react_native_pods.rb only added -DRCT_REMOVE_LEGACY_ARCH=1 via add_compiler_flag_to_project, which sets OTHER_CFLAGS / OTHER_CPLUSPLUSFLAGS. Swift does not consume those; it reads SWIFT_ACTIVE_COMPILATION_CONDITIONS. As a result, #if RCT_REMOVE_LEGACY_ARCH in Swift was silently always false, and templates that need to keep sourceURLForBridge: for legacy-arch builds while compiling cleanly against legacy-arch-removed builds had no way to express that.

Adds two helpers in ReactNativePodsUtils:

  • add_swift_active_compilation_condition_to_project(installer, condition)
  • remove_swift_active_compilation_condition_from_project(installer, condition)

Both are additive and idempotent: they normalise the existing SWIFT_ACTIVE_COMPILATION_CONDITIONS value (which may be nil, a string, or an array) into an array, preserve $(inherited) and any pre-existing conditions such as DEBUG, and dedupe on insert. Repeated pod install runs produce stable output.

react_native_pods.rb now calls the add/remove helpers alongside the existing C-flag add/remove inside the RCT_REMOVE_LEGACY_ARCH env-var branch.

Changelog:
[iOS][Added] - Propagate RCT_REMOVE_LEGACY_ARCH into SWIFT_ACTIVE_COMPILATION_CONDITIONS so Swift code in apps and the community template can branch on #if !RCT_REMOVE_LEGACY_ARCH, matching the existing C/C++ -DRCT_REMOVE_LEGACY_ARCH=1 flag.

Differential Revision: D106466169

@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 May 27, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 27, 2026

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

…TIONS`

Summary:
Mirrors the existing C/C++ `-DRCT_REMOVE_LEGACY_ARCH=1` flag into Swift's `SWIFT_ACTIVE_COMPILATION_CONDITIONS` so Swift sources (notably user `AppDelegate.swift` files derived from the community template) can branch on `#if !RCT_REMOVE_LEGACY_ARCH`.

Until now, `react_native_pods.rb` only added `-DRCT_REMOVE_LEGACY_ARCH=1` via `add_compiler_flag_to_project`, which sets `OTHER_CFLAGS` / `OTHER_CPLUSPLUSFLAGS`. Swift does not consume those; it reads `SWIFT_ACTIVE_COMPILATION_CONDITIONS`. As a result, `#if RCT_REMOVE_LEGACY_ARCH` in Swift was silently always false, and templates that need to keep `sourceURLForBridge:` for legacy-arch builds while compiling cleanly against legacy-arch-removed builds had no way to express that.

Adds two helpers in `ReactNativePodsUtils`:

- `add_swift_active_compilation_condition_to_project(installer, condition)`
- `remove_swift_active_compilation_condition_from_project(installer, condition)`

Both are additive and idempotent: they normalise the existing `SWIFT_ACTIVE_COMPILATION_CONDITIONS` value (which may be nil, a string, or an array) into an array, preserve `$(inherited)` and any pre-existing conditions such as `DEBUG`, and dedupe on insert. Repeated `pod install` runs produce stable output.

`react_native_pods.rb` now calls the add/remove helpers alongside the existing C-flag add/remove inside the `RCT_REMOVE_LEGACY_ARCH` env-var branch.

Changelog:
[iOS][Added] - Propagate `RCT_REMOVE_LEGACY_ARCH` into `SWIFT_ACTIVE_COMPILATION_CONDITIONS` so Swift code in apps and the community template can branch on `#if !RCT_REMOVE_LEGACY_ARCH`, matching the existing C/C++ `-DRCT_REMOVE_LEGACY_ARCH=1` flag.

Differential Revision: D106466169
christophpurrer added a commit to christophpurrer/react-native-community-template that referenced this pull request May 27, 2026
…acy arch removal

The sourceURLForBridge: method will be removed from RCTBridgeDelegate in
facebook/react-native#56831 due to the RCT_REMOVE_LEGACY_ARCH
clean up. Then the override no longer overrides anything and
fails Swift compilation. bundleURL() — already present below — is the
replacement API on RCTReactNativeFactoryDelegate.

This change depends on facebook/react-native#56974
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. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant