Skip to content

Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG in the Debug config - #244

Closed
radoslawrolka wants to merge 1 commit into
react-native-community:mainfrom
radoslawrolka:rolkrado/add-swift-debug
Closed

Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG in the Debug config#244
radoslawrolka wants to merge 1 commit into
react-native-community:mainfrom
radoslawrolka:rolkrado/add-swift-debug

Conversation

@radoslawrolka

@radoslawrolka radoslawrolka commented Jul 17, 2026

Copy link
Copy Markdown

Continuation in react/react-native#57914

## Summary:

The app template's AppDelegate.swift gates the Metro bundle URL behind #if DEBUG (falling back to a non-existent main.jsbundle otherwise). In Swift, #if DEBUG is controlled by SWIFT_ACTIVE_COMPILATION_CONDITIONS, not by GCC_PREPROCESSOR_DEFINITIONS (which only affects C/ObjC/C++).

Today this flag is not committed in project.pbxproj; it is injected at pod install time by react_native_post_install (react_native_pods.rb), which calls set_build_setting for SWIFT_ACTIVE_COMPILATION_CONDITIONS = ["$(inherited)", "DEBUG"] on the user project's Debug config.

That means any setup that does not run CocoaPods (e.g. Swift Package Manager react-native experimental setup) never gets the flag, so #if DEBUG is false even in Debug builds. bundleURL() then returns nil and the app fails to launch with "No script url provided ... unsanitizedScriptURLString = (null)", even though Metro is running.

Baking the setting into the template makes Debug builds work regardless of the dependency manager and matches the value CocoaPods already sets, so CocoaPods-based apps are unaffected.

## Changelog:

[IOS] [FIXED] - added missing SWIFT_ACTIVE_COMPILATION_CONDITIONS in debug config

## Test Plan:

building app without coocapods (react/react-native #57332)

The app template's AppDelegate.swift gates the Metro bundle URL behind
`#if DEBUG` (falling back to a non-existent main.jsbundle otherwise). In
Swift, `#if DEBUG` is controlled by SWIFT_ACTIVE_COMPILATION_CONDITIONS,
not by GCC_PREPROCESSOR_DEFINITIONS (which only affects C/ObjC/C++).

Today this flag is not committed in project.pbxproj; it is injected at
`pod install` time by react_native_post_install (react_native_pods.rb),
which calls set_build_setting for SWIFT_ACTIVE_COMPILATION_CONDITIONS =
["$(inherited)", "DEBUG"] on the user project's Debug config.

That means any setup that does not run CocoaPods (e.g. Swift Package
Manager react-native experimental setup) never gets the flag, so `#if DEBUG` is false even in Debug
builds. bundleURL() then returns nil and the app fails to launch with
"No script url provided ... unsanitizedScriptURLString = (null)", even
though Metro is running.

Baking the setting into the template makes Debug builds work regardless
of the dependency manager and matches the value CocoaPods already sets,
so CocoaPods-based apps are unaffected.
@chrfalch

Copy link
Copy Markdown

I think we should merge this one, @radoslawrolka :) Makes a lot of sense - since this is the App's code it should be here - and not in the SwiftPM manifest generators.

@radoslawrolka
radoslawrolka marked this pull request as ready for review July 24, 2026 07:58
@cortinico
cortinico requested a review from cipolleschi July 24, 2026 15:43
@radoslawrolka

Copy link
Copy Markdown
Author

cc @cortinico @cipolleschi

@cipolleschi cipolleschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR. however, that's not the best way to handle it as everyone would have to modify their project. A better way would be to open a PR against React Native and modify the scripts that configure the project to add that flag.
Do you mind doing that?

@radoslawrolka

Copy link
Copy Markdown
Author

Created the react/react-native#57914

meta-codesync Bot pushed a commit to react/react-native that referenced this pull request Aug 13, 2026
…57914)

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.

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

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

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #57914

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

Reviewed By: Abbondanzo

Differential Revision: D115736551

Pulled By: cipolleschi

fbshipit-source-id: 1e42ca26ac1992bfa827ce85a63cf4564d313e15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants