titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

fix(ios): fixed Swift compilation conditions and flags

Open hbugdoll opened this issue 1 month ago • 3 comments

Introduction:

These warnings have caused confusion for several times, particularly as false positive errors ([1], [2], [3], [4], [5]):

warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'DEPLOYTYPE=development') ...
warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than '__LOG__ID__=******')  ...
warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'DEBUG=1')  ...
warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'LAUNCHSCREEN_STORYBOARD=1')  ...
warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'DEFAULT_BGCOLOR_RED=1')  ...
warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'DEFAULT_BGCOLOR_GREEN=1')  ...
warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'DEFAULT_BGCOLOR_BLUE=1')  ...
warning: Conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'DISABLE_TI_LOG_SERVER=1')  ...

The values of the Swift compiler variable SWIFT_ACTIVE_COMPILATION_CONDITIONS are copied from GCC_PREPROCESSOR_DEFINITIONS in iphone/iphone/Titanium.xcodeproj/project.pbxproj. But SWIFT_ACTIVE_COMPILATION_CONDITIONS doesn't allow key-value pairs, only a list of conditional compilation flags like in TI_SYMBOL_MACROS – that is why the above warnings are raised.

[!NOTE] My initial naive solution did not work because the Swift compiler does not support key-value compiler flags at all!

But do we even need key-value compiler flags? Of course, it's a simple "traditional" way – easy to maintain. But I don't think so in this case. So far, they have only been used in main.m. And in my opinion, compiler optimizations will make the minimal performance advantage for these few values obsolete.

  1. The DEPLOYTYPE flag was no longer used at all; instead, TI_APPLICATION_DEPLOYTYPE is available.
  2. The __LOG__ID__ flag is not needed because it has exactly the same value as TI_APPLICATION_GUID; instead, introduction of a conditional flag LOGTOFILE is sufficient.
  3. Only the following flags remain: TI_LOG_SERVER_PORT and DEFAULT_BGCOLOR_RED/..._GREEN/..._BLUE. These four can easily be replaced as templated values in writeMain() too, analogous to App-ID/GUID/etc.

Description:

  • ~~splitted~~ transferred non-key-value flags of GCC_PREPROCESSOR_DEFINITIONS for use with Swift ~~into~~ to
    • SWIFT_ACTIVE_COMPILATION_CONDITIONS (conditional compilation flags)
    • ~~andOTHER_SWIFT_FLAGS (key-value pairs)~~
  • therefore, added new array swiftConds to clearly distinguish from gccDefs (this also prevents similar programming mistakes in the future) and a new config variable SWIFT_CONDITIONS in project.xcconfig
  • replaced all current key-value compiler flags (see Note above)
  • additionally made some "chore":
    • changed TI_APPLICATION_DEPLOYTYPE into TI_APPLICATION_DEPLOY_TYPE to consistently take camel case into account (comp. with deployType)
    • changed templated value __APP_DEPLOY_TYPE__ (=buildType) into __BUILD_TYPE__ to avoid confusion with __DEPLOY_TYPE__ (=deployType)

hbugdoll avatar Nov 28 '25 00:11 hbugdoll

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

socket-security[bot] avatar Nov 28 '25 08:11 socket-security[bot]

Changes from initial draft:

  • ~~replaced undocumented SWIFT_COMPILER_FLAGS with OTHER_SWIFT_FLAGS^1~~
  • use of JS arrow functions

hbugdoll avatar Nov 28 '25 08:11 hbugdoll

New changes:

  • rework: replaced key-value compiler flags overall

hbugdoll avatar Dec 10 '25 07:12 hbugdoll