@@ -363,8 +363,22 @@ public struct XCFramework: Hashable, Sendable {
363363 /// The minimum XCFramework version required to support mergeable metadata.
364364 @_spi ( Testing) public static let mergeableMetadataVersion = Version ( 1 , 1 )
365365
366+ /// Whether the platform ships one slice per architecture (no fat binaries).
366367 static func hasPerArchSlices( _ platform: String ) -> Bool {
367- return platform == " linux "
368+ // Triple-sys spellings (e.g. "macos") — from findLibrary.
369+ if BuildVersion . Platform ( platform: platform, environment: nil ) != nil {
370+ return false
371+ }
372+ // SDK names from Info.plist.
373+ let appleSDKNames : Set < String > = [
374+ " macosx " ,
375+ " iphoneos " , " iphonesimulator " ,
376+ " appletvos " , " appletvsimulator " ,
377+ " watchos " , " watchsimulator " ,
378+ " xros " , " xrsimulator " ,
379+ " driverkit " ,
380+ ]
381+ return !appleSDKNames. contains ( platform)
368382 }
369383
370384 /// Searches the `libraries` based on the current SDK being used.
@@ -384,10 +398,9 @@ public struct XCFramework: Hashable, Sendable {
384398 lib. supportedPlatform == platform && ( lib. platformVariant ?? " " ) == platformVariant
385399 } . first
386400 }
387- // Linux ships per-arch XCFramework slices and typically omits SupportedPlatformVariant, so for
388- // that platform require exactly one target arch and allow a no-variant fallback.
389- guard architectures. count == 1 else { return nil }
390- let targetArch = architectures [ 0 ]
401+ // Non-Apple platforms ship per-arch XCFramework slices and typically omit SupportedPlatformVariant, so for
402+ // those platforms, require exactly one target arch and allow a no-variant fallback.
403+ guard let targetArch = architectures. only else { return nil }
391404 let variants : [ String ] = platformVariant. isEmpty ? [ " " ] : [ platformVariant, " " ]
392405 for variant in variants {
393406 if let match = libraries. first ( where: {
@@ -409,23 +422,17 @@ extension XCFramework {
409422 let platformVariant : String ?
410423 let architectures : [ String ]
411424
412- // Per-arch slice platforms — sibling slices must not collide on `(platform, variant)` alone.
413- private var usesPerArchSlices : Bool { XCFramework . hasPerArchSlices ( platform) }
414-
415425 func hash( into hasher: inout Hasher ) {
416426 // identifier is only used for tracking the offending library
417427 hasher. combine ( platform)
418428 hasher. combine ( platformVariant)
419- if usesPerArchSlices {
420- hasher. combine ( architectures)
421- }
429+ hasher. combine ( architectures)
422430 }
423431
424432 static func == ( lhs: LibraryKey , rhs: LibraryKey ) -> Bool {
425- guard lhs. platform == rhs. platform, lhs. platformVariant == rhs. platformVariant else {
426- return false
427- }
428- return lhs. usesPerArchSlices ? ( lhs. architectures == rhs. architectures) : true
433+ return lhs. platform == rhs. platform
434+ && lhs. platformVariant == rhs. platformVariant
435+ && lhs. architectures == rhs. architectures
429436 }
430437 }
431438
@@ -498,7 +505,12 @@ extension XCFramework {
498505 throw XCFrameworkValidationError . headerPathNotSupported ( libraryType: library. libraryType, libraryIdentifier: library. libraryIdentifier)
499506 }
500507
501- let ( added, oldMember) = libraryKeys. insert ( LibraryKey ( identifier: library. libraryIdentifier, platform: library. supportedPlatform, platformVariant: library. platformVariant, architectures: library. supportedArchitectures. sorted ( ) ) )
508+ // Per-arch platforms discriminate slices on arch; fat-binary platforms don't.
509+ var keyArchitectures : [ String ] = [ ]
510+ if Self . hasPerArchSlices ( library. supportedPlatform) {
511+ keyArchitectures = library. supportedArchitectures. sorted ( )
512+ }
513+ let ( added, oldMember) = libraryKeys. insert ( LibraryKey ( identifier: library. libraryIdentifier, platform: library. supportedPlatform, platformVariant: library. platformVariant, architectures: keyArchitectures) )
502514 guard added == true else {
503515 throw XCFrameworkValidationError . conflictingLibraryDefinitions ( libraryIdentifier: oldMember. identifier, otherLibraryIdentifier: library. libraryIdentifier)
504516 }
0 commit comments