@@ -137,6 +137,7 @@ extension ProjectModel {
137137 case SWIFT_WARNINGS_AS_ERRORS_GROUPS
138138 }
139139
140+ @available ( * , deprecated, message: " Use subscripts to set platform-specific SingleValueSetting/MultipleValueSettings instead " )
140141 public enum Declaration : String , Hashable , CaseIterable , Sendable {
141142 case ARCHS
142143 case GCC_PREPROCESSOR_DEFINITIONS
@@ -186,8 +187,6 @@ extension ProjectModel {
186187 }
187188 }
188189
189- public var platformSpecificSettings = [ Platform: [ Declaration: [ String] ] ] ( )
190-
191190 public init ( ) {
192191 var settings : [ Declaration : [ String ] ] = [ : ]
193192 for declaration in Declaration . allCases {
@@ -201,6 +200,13 @@ extension ProjectModel {
201200
202201 private( set) var singleValueSettings : OrderedDictionary < String , String > = [ : ]
203202 private( set) var multipleValueSettings : OrderedDictionary < String , [ String ] > = [ : ]
203+ private( set) var singleValuePlatformSpecificSettings = [ Platform : OrderedDictionary < String , String > ] ( )
204+ private( set) var multipleValuePlatformSpecificSettings = [ Platform : OrderedDictionary < String , [ String ] > ] ( )
205+
206+ // Kept for API compatibility
207+ @available ( * , deprecated, message: " Use subscripts to set platform-specific settings instead " )
208+ public var platformSpecificSettings = [ Platform: [ Declaration: [ String] ] ] ( )
209+
204210
205211 public subscript( _ setting: SingleValueSetting ) -> String ? {
206212 get { singleValueSettings [ setting. rawValue] }
@@ -221,6 +227,16 @@ extension ProjectModel {
221227 get { multipleValueSettings [ setting] }
222228 set { multipleValueSettings [ setting] = newValue }
223229 }
230+
231+ public subscript( _ setting: SingleValueSetting , platform: Platform ) -> String ? {
232+ get { singleValuePlatformSpecificSettings [ platform] ? [ setting. rawValue] }
233+ set { singleValuePlatformSpecificSettings [ platform, default: . init( ) ] [ setting. rawValue] = newValue }
234+ }
235+
236+ public subscript( _ setting: MultipleValueSetting , platform: Platform ) -> [ String ] ? {
237+ get { multipleValuePlatformSpecificSettings [ platform] ? [ setting. rawValue] }
238+ set { multipleValuePlatformSpecificSettings [ platform, default: . init( ) ] [ setting. rawValue] = newValue }
239+ }
224240 }
225241}
226242
@@ -325,6 +341,23 @@ extension ProjectModel.BuildSettings: Codable {
325341 self . platformSpecificSettings [ platform, default: [ : ] ] [ declaration] = value
326342 }
327343 }
344+ let declarationValues = Set ( Declaration . allCases. map ( \. rawValue) )
345+ for key in SingleValueSetting . allCases {
346+ if declarationValues. contains ( key. rawValue) {
347+ continue
348+ }
349+ if let value = try container. decodeIfPresent ( String . self, forKey: StringKey ( " \( key. rawValue) [ \( condition) ] " ) ) {
350+ self [ key, platform] = value
351+ }
352+ }
353+ for key in MultipleValueSetting . allCases {
354+ if declarationValues. contains ( key. rawValue) {
355+ continue
356+ }
357+ if let value = try container. decodeIfPresent ( [ String ] . self, forKey: StringKey ( " \( key. rawValue) [ \( condition) ] " ) ) {
358+ self [ key, platform] = value
359+ }
360+ }
328361 }
329362 }
330363 }
@@ -351,5 +384,21 @@ extension ProjectModel.BuildSettings: Codable {
351384 }
352385 }
353386 }
387+
388+ for (platform, table) in singleValuePlatformSpecificSettings {
389+ for condition in platform. asConditionStrings {
390+ for (key, value) in table {
391+ try container. encode ( value, forKey: StringKey ( " \( key) [ \( condition) ] " ) )
392+ }
393+ }
394+ }
395+
396+ for (platform, table) in multipleValuePlatformSpecificSettings {
397+ for condition in platform. asConditionStrings {
398+ for (key, value) in table {
399+ try container. encode ( value, forKey: StringKey ( " \( key) [ \( condition) ] " ) )
400+ }
401+ }
402+ }
354403 }
355404}
0 commit comments