Skip to content

[IOS] [FIXED] Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG when injecting SPM - #57914

Closed
radoslawrolka wants to merge 1 commit into
react:mainfrom
radoslawrolka:spm-swift-active-compilation-conditions
Closed

[IOS] [FIXED] Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG when injecting SPM#57914
radoslawrolka wants to merge 1 commit into
react:mainfrom
radoslawrolka:spm-swift-active-compilation-conditions

Conversation

@radoslawrolka

@radoslawrolka radoslawrolka commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary:

Swift's #if DEBUG is gated by SWIFT_ACTIVE_COMPILATION_CONDITIONS, not by GCC_PREPROCESSOR_DEFINITIONS (which only reaches C/ObjC/C++). The app template does not commit that setting; CocoaPods injects it at pod install time (react_native_post_install -> set_build_setting
SWIFT_ACTIVE_COMPILATION_CONDITIONS = ["$(inherited)", "DEBUG"] on Debug).

An app set up with the experimental SwiftPM support never runs CocoaPods, so #if DEBUG is false even in a Debug build: AppDelegate.swift's bundleURL() skips the Metro URL and falls back to a main.jsbundle a Debug build never produced, and the app dies at launch with "No script url provided ... unsanitizedScriptURLString = (null)" while Metro is running.

Info: react-native-community/template#244

Changelog:

Inject the setting from spm add/update alongside the other React build settings, into debug-flavored configurations only (the same flavorForBuildConfiguration test that selects the debug xcframeworks), so a config linking the debug binaries also compiles its Swift with DEBUG.

Test Plan:

  1. Build spm-only rn app in debug
    • App will fail to connect to the Metro
  2. Apply changes and run react-native spm
  3. Build again
    • App will work as expected in debug and Metro will be connected

Swift's `#if DEBUG` is gated by SWIFT_ACTIVE_COMPILATION_CONDITIONS, not by
GCC_PREPROCESSOR_DEFINITIONS (which only reaches C/ObjC/C++). The app template
does not commit that setting; CocoaPods injects it at `pod install` time
(react_native_post_install -> set_build_setting
SWIFT_ACTIVE_COMPILATION_CONDITIONS = ["$(inherited)", "DEBUG"] on Debug).

An app set up with the experimental SwiftPM support never runs CocoaPods, so
`#if DEBUG` is false even in a Debug build: AppDelegate.swift's `bundleURL()`
skips the Metro URL and falls back to a main.jsbundle a Debug build never
produced, and the app dies at launch with "No script url provided ...
unsanitizedScriptURLString = (null)" while Metro is running.

Inject the setting from `spm add`/`update` alongside the other React build
settings, into debug-flavored configurations only (the same
flavorForBuildConfiguration test that selects the debug xcframeworks), so a
config linking the debug binaries also compiles its Swift with DEBUG.

Doing it in the injector rather than in the app template fixes existing apps
too, and keeps the setting on the one code path that knows a project is
SwiftPM-integrated.

The merge is additive and reversible like every other injected setting: a
config that already defines DEBUG is left byte-identical. That required
tightening the "already present" test in mergeReactBuildSettings from a
substring match to token membership -- it now recognizes the scalar form
(`"$(inherited) DEBUG"`) that addArrayStringValues' exact-member dedupe misses
(previously it would have promoted the scalar to an array and re-appended,
an edit the marker has no record of and `deinit` could never reverse), while
no longer reading a user's `MY_DEBUG_FLAG` as DEBUG.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@meta-cla

meta-cla Bot commented Aug 12, 2026

Copy link
Copy Markdown

Hi @radoslawrolka!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@radoslawrolka

Copy link
Copy Markdown
Contributor Author

@meta-cla - signed cla (done)

cc @cipolleschi (mention from react-native-community/template#244)

@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 Aug 12, 2026
@meta-cla

meta-cla Bot commented Aug 12, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 12, 2026
@meta-codesync

meta-codesync Bot commented Aug 12, 2026

Copy link
Copy Markdown

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D115736551.

@meta-codesync meta-codesync Bot closed this in 4433cdb Aug 13, 2026
@meta-codesync

meta-codesync Bot commented Aug 13, 2026

Copy link
Copy Markdown

@cipolleschi merged this pull request in 4433cdb.

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. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants