@@ -163,11 +163,17 @@ let attributeGraphCondition = envBoolValue("ATTRIBUTEGRAPH", default: buildForDa
163163var sharedCSettings : [ CSetting ] = [
164164 . unsafeFlags( [ " -I " , libSwiftPath] , . when( platforms: . nonDarwinPlatforms) ) ,
165165 . define( " NDEBUG " , . when( configuration: . release) ) ,
166+ // Rewrite malloc() to malloc_type_malloc() for type-isolated allocation buckets (xzone malloc).
167+ . unsafeFlags( [ " -ftyped-memory-operations " ] , . when( platforms: . darwinPlatforms) ) ,
166168]
167169
168170var sharedCxxSettings : [ CXXSetting ] = [
169171 . unsafeFlags( [ " -I " , libSwiftPath] , . when( platforms: . nonDarwinPlatforms) ) ,
170172 . define( " NDEBUG " , . when( configuration: . release) ) ,
173+ // Rewrite malloc() to malloc_type_malloc() for type-isolated allocation buckets (xzone malloc).
174+ . unsafeFlags( [ " -ftyped-memory-operations " ] , . when( platforms: . darwinPlatforms) ) ,
175+ // Rewrite operator new/delete to typed variants (operator new(size_t, std::__type_descriptor_t)).
176+ . unsafeFlags( [ " -ftyped-cxx-new-delete " ] , . when( platforms: . darwinPlatforms) ) ,
171177]
172178
173179var sharedSwiftSettings : [ SwiftSetting ] = [
@@ -226,6 +232,9 @@ extension Target {
226232}
227233
228234extension [ Platform ] {
235+ static var darwinPlatforms : [ Platform ] {
236+ [ . macOS, . iOS, . tvOS, . watchOS, . visionOS, . macCatalyst]
237+ }
229238 static var nonDarwinPlatforms : [ Platform ] {
230239 [ . linux, . android, . wasi, . openbsd, . windows]
231240 }
@@ -242,16 +251,30 @@ let swiftClonePlugin = Target.plugin(
242251
243252let platformTarget = Target . target (
244253 name: " Platform " ,
245- cSettings: [
254+ cSettings: sharedCSettings + [
246255 . define( " _GNU_SOURCE " , . when( platforms: [ . linux] ) ) ,
247256 ]
248257)
258+ let swiftCorelibsCoreFoundationTarget = Target . target (
259+ name: " SwiftCorelibsCoreFoundation "
260+ )
261+ let utilitiesTarget = Target . target (
262+ name: " Utilities " ,
263+ dependencies: [
264+ . target( name: platformTarget. name) ,
265+ . target( name: swiftCorelibsCoreFoundationTarget. name, condition: . when( platforms: . nonDarwinPlatforms) ) ,
266+ ] ,
267+ cxxSettings: sharedCxxSettings
268+ )
249269// FIXME: Merge into one target
250270// OpenAttributeGraph is a C++ & Swift mix target.
251271// The SwiftPM support for such usage is still in progress.
252272let openAttributeGraphCxxTarget = Target . target (
253273 name: " OpenAttributeGraphCxx " ,
254- dependencies: [ . target( name: platformTarget. name) ] ,
274+ dependencies: [
275+ . target( name: platformTarget. name) ,
276+ . target( name: utilitiesTarget. name) ,
277+ ] ,
255278 cSettings: sharedCSettings + [
256279 . define( " __COREFOUNDATION_FORSWIFTFOUNDATIONONLY__ " , to: " 1 " , . when( platforms: . nonDarwinPlatforms) ) ,
257280 ] ,
@@ -279,6 +302,14 @@ let openAttributeGraphShimsTarget = Target.target(
279302
280303// MARK: - Test Targets
281304
305+ let utilitiesTestsTarget = Target . testTarget (
306+ name: " UtilitiesTests " ,
307+ dependencies: [
308+ . target( name: utilitiesTarget. name) ,
309+ ] ,
310+ cxxSettings: [ . define( " SWIFT_TESTING " ) ] ,
311+ swiftSettings: [ . interoperabilityMode( . Cxx) ]
312+ )
282313let openAttributeGraphCxxTestsTarget = Target . testTarget (
283314 name: " OpenAttributeGraphCxxTests " ,
284315 dependencies: [
@@ -324,6 +355,8 @@ let package = Package(
324355 targets: [
325356 swiftClonePlugin,
326357 platformTarget,
358+ swiftCorelibsCoreFoundationTarget,
359+ utilitiesTarget,
327360 openAttributeGraphTarget,
328361 openAttributeGraphCxxTarget,
329362 openAttributeGraphShimsTarget,
@@ -335,6 +368,7 @@ if compatibilityTestCondition {
335368 openAttributeGraphCompatibilityTestsTarget. addAGSettings ( )
336369} else {
337370 package . targets += [
371+ utilitiesTestsTarget,
338372 openAttributeGraphCxxTestsTarget,
339373 openAttributeGraphShimsTestsTarget,
340374 ]
0 commit comments