[IOS] [FIXED] Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG when injecting SPM - #57914
[IOS] [FIXED] Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG when injecting SPM#57914radoslawrolka wants to merge 1 commit into
Conversation
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>
|
Hi @radoslawrolka! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
@meta-cla - signed cla (done) cc @cipolleschi (mention from react-native-community/template#244) |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D115736551. |
Summary:
Swift's
#if DEBUGis 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 atpod installtime (react_native_post_install -> set_build_settingSWIFT_ACTIVE_COMPILATION_CONDITIONS = ["$(inherited)", "DEBUG"] on Debug).
An app set up with the experimental SwiftPM support never runs CocoaPods, so
#if DEBUGis false even in a Debug build: AppDelegate.swift'sbundleURL()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/updatealongside 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:
react-native spm