Skip to content

Commit f204c90

Browse files
committed
Update XCFramework logic
This hardcoded platform and architectures before, make it mor generic to handle macOS on arm64.
1 parent 3b3a55c commit f204c90

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,9 +1763,9 @@ public class BuildPlan {
17631763
return nil
17641764
}
17651765

1766-
// Check that it supports macOS.
1766+
// Check that it supports the target platform and architecture.
17671767
guard let library = info.libraries.first(where: {
1768-
$0.platform == "macos" && $0.architectures.contains(Triple.Arch.x86_64.rawValue)
1768+
return $0.platform == buildParameters.triple.os.asXCFrameworkPlatformString && $0.architectures.contains(buildParameters.triple.arch.rawValue)
17691769
}) else {
17701770
diagnostics.emit(error: """
17711771
artifact '\(target.name)' does not support the target platform and architecture \
@@ -1885,3 +1885,15 @@ private func generateResourceInfoPlist(
18851885
try fileSystem.writeIfChanged(path: path, bytes: stream.bytes)
18861886
return true
18871887
}
1888+
1889+
fileprivate extension Triple.OS {
1890+
/// Returns a representation of the receiver that can be compared with platform strings declared in an XCFramework.
1891+
var asXCFrameworkPlatformString: String? {
1892+
switch self {
1893+
case .darwin, .linux, .wasi, .windows:
1894+
return nil // XCFrameworks do not support any of these platforms today.
1895+
case .macOS:
1896+
return "macos"
1897+
}
1898+
}
1899+
}

Sources/Workspace/InitPackage.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public final class InitPackage {
153153

154154
var param = ".\(platform.manifestName)("
155155
if supportedPlatform.isManifestAPIAvailable {
156-
if platform == .macOS {
157-
param += ".v10_\(version.minor)"
156+
if version.minor > 0 {
157+
param += ".v\(version.major)_\(version.minor)"
158158
} else {
159159
param += ".v\(version.major)"
160160
}
@@ -518,11 +518,11 @@ extension PackageModel.Platform {
518518

519519
extension SupportedPlatform {
520520
var isManifestAPIAvailable: Bool {
521-
if platform == .macOS {
522-
guard self.version.major == 10, self.version.patch == 0 else {
521+
if platform == .macOS && self.version.major == 10 {
522+
guard self.version.patch == 0 else {
523523
return false
524524
}
525-
} else if [Platform.iOS, .watchOS, .tvOS].contains(platform) {
525+
} else if [Platform.macOS, .iOS, .watchOS, .tvOS].contains(platform) {
526526
guard self.version.minor == 0, self.version.patch == 0 else {
527527
return false
528528
}
@@ -531,14 +531,16 @@ extension SupportedPlatform {
531531
}
532532

533533
switch platform {
534-
case .macOS:
534+
case .macOS where version.major == 10:
535535
return (10...15).contains(version.minor)
536+
case .macOS:
537+
return (11...11).contains(version.major)
536538
case .iOS:
537-
return (8...13).contains(version.major)
539+
return (8...14).contains(version.major)
538540
case .tvOS:
539-
return (9...13).contains(version.major)
541+
return (9...14).contains(version.major)
540542
case .watchOS:
541-
return (2...6).contains(version.major)
543+
return (2...7).contains(version.major)
542544

543545
default:
544546
return false

0 commit comments

Comments
 (0)