TargetPlatform.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2020 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. /// The target platform that the framework is built for.
  18. enum TargetPlatform: CaseIterable {
  19. /// Binaries to target iOS devices.
  20. case iOSDevice
  21. /// Binaries to target iOS simulators.
  22. case iOSSimulator
  23. /// Binaries to target Catalyst.
  24. case catalyst
  25. /// Binaries to target macOS.
  26. case macOS
  27. /// Binaries to target tvOS.
  28. case tvOSDevice
  29. /// Binaries to target tvOS simulators.
  30. case tvOSSimulator
  31. /// Binaries to target tvOS.
  32. case watchOSDevice
  33. /// Binaries to target tvOS simulators.
  34. case watchOSSimulator
  35. /// Valid architectures to be built for the platform.
  36. var archs: [Architecture] {
  37. switch self {
  38. case .iOSDevice: return Included32BitIOS.include32 ? [.armv7, .arm64] : [.arm64]
  39. // Include arm64 slices in the simulator for Apple silicon Macs.
  40. case .iOSSimulator: return Included32BitIOS
  41. .include32 ? [.i386, .x86_64, .arm64] : [.x86_64, .arm64]
  42. // TODO: Evaluate x86_64h slice. Previous builds were limited to x86_64.
  43. case .catalyst: return [.x86_64, .arm64]
  44. case .macOS: return [.x86_64, .arm64]
  45. case .tvOSDevice: return [.arm64]
  46. case .tvOSSimulator: return [.x86_64, .arm64]
  47. case .watchOSDevice: return [.arm64_32, .arm64]
  48. case .watchOSSimulator: return [.x86_64, .arm64]
  49. }
  50. }
  51. /// Name of the SDK as used by `xcodebuild` for the target platforms.
  52. var sdkName: String {
  53. switch self {
  54. case .iOSDevice: return "iphoneos"
  55. case .iOSSimulator: return "iphonesimulator"
  56. case .catalyst: return "macosx"
  57. case .macOS: return "macosx"
  58. case .tvOSDevice: return "appletvos"
  59. case .tvOSSimulator: return "appletvsimulator"
  60. case .watchOSDevice: return "watchos"
  61. case .watchOSSimulator: return "watchsimulator"
  62. }
  63. }
  64. /// The build name. Distinguished from sdkName to disambiguate catalyst and macOS.
  65. var buildName: String {
  66. switch self {
  67. case .catalyst: return "catalyst"
  68. default: return sdkName
  69. }
  70. }
  71. /// Name of the directory that builds go into, autogenerated from Xcode.
  72. var buildDirName: String {
  73. switch self {
  74. case .iOSDevice: return "Release-iphoneos"
  75. case .iOSSimulator: return "Release-iphonesimulator"
  76. case .catalyst: return "Release-maccatalyst"
  77. case .macOS: return "Release"
  78. case .tvOSDevice: return "Release-appletvos"
  79. case .tvOSSimulator: return "Release-appletvsimulator"
  80. case .watchOSDevice: return "Release-watchos"
  81. case .watchOSSimulator: return "Release-watchsimulator"
  82. }
  83. }
  84. }
  85. /// Different architectures to build frameworks for.
  86. enum Architecture: String, CaseIterable {
  87. case arm64
  88. case arm64_32
  89. case armv7
  90. case i386
  91. case x86_64
  92. case x86_64h // x86_64h, Haswell, used for Mac Catalyst
  93. }
  94. enum Included32BitIOS {
  95. fileprivate static var include32 = false
  96. static func set() {
  97. include32 = true
  98. }
  99. }