Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG in the Debug config - #244
Closed
radoslawrolka wants to merge 1 commit into
Closed
Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG in the Debug config#244radoslawrolka wants to merge 1 commit into
radoslawrolka wants to merge 1 commit into
Conversation
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.
|
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
marked this pull request as ready for review
July 24, 2026 07:58
Author
cipolleschi
requested changes
Aug 12, 2026
cipolleschi
left a comment
Contributor
There was a problem hiding this comment.
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?
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 DEBUGis 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 atpod installtime 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 DEBUGis 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)