Skip to content

[0.87] Set SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG when injecting SPM #1374

Description

@cipolleschi

Target Branch

0.87

Link to commit or PR to be picked

react/react-native#57914

Landed on main as react/react-native@4433cdb

Description

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_installset_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 that a Debug build never produced. The app dies at launch with No script url provided ... unsanitizedScriptURLString = (null) while Metro is running.

This makes SwiftPM Debug builds unusable on 0.87 out of the box, which is why it is worth picking.

The fix injects 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). 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. Related context: react-native-community/template#244.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type Pick RequestPick requests to include commits inside a React Native release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions