TargetPlatform.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /// Valid architectures to be built for the platform.
  32. var archs: [Architecture] {
  33. switch self {
  34. case .iOSDevice: return Included32BitIOS.include32 ? [.armv7, .arm64] : [.arm64]
  35. // Include arm64 slices in the simulator for Apple silicon Macs.
  36. case .iOSSimulator: return Included32BitIOS
  37. .include32 ? [.i386, .x86_64, .arm64] : [.x86_64, .arm64]
  38. // TODO: Evaluate x86_64h slice. Previous builds were limited to x86_64.
  39. case .catalyst: return [.x86_64, .arm64]
  40. case .macOS: return [.x86_64, .arm64]
  41. case .tvOSDevice: return [.arm64]
  42. case .tvOSSimulator: return [.x86_64, .arm64]
  43. }
  44. }
  45. /// Name of the SDK as used by `xcodebuild` for the target platforms.
  46. var sdkName: String {
  47. switch self {
  48. case .iOSDevice: return "iphoneos"
  49. case .iOSSimulator: return "iphonesimulator"
  50. case .catalyst: return "macosx"
  51. case .macOS: return "macosx"
  52. case .tvOSDevice: return "appletvos"
  53. case .tvOSSimulator: return "appletvsimulator"
  54. }
  55. }
  56. /// The build name. Distinguished from sdkName to disambiguate catalyst and macOS.
  57. var buildName: String {
  58. switch self {
  59. case .catalyst: return "catalyst"
  60. default: return sdkName
  61. }
  62. }
  63. /// Name of the directory that builds go into, autogenerated from Xcode.
  64. var buildDirName: String {
  65. switch self {
  66. case .iOSDevice: return "Release-iphoneos"
  67. case .iOSSimulator: return "Release-iphonesimulator"
  68. case .catalyst: return "Release-maccatalyst"
  69. case .macOS: return "Release"
  70. case .tvOSDevice: return "Release-appletvos"
  71. case .tvOSSimulator: return "Release-appletvsimulator"
  72. }
  73. }
  74. }
  75. /// Different architectures to build frameworks for.
  76. enum Architecture: String, CaseIterable {
  77. case arm64
  78. case armv7
  79. case i386
  80. case x86_64
  81. case x86_64h // x86_64h, Haswell, used for Mac Catalyst
  82. }
  83. enum Included32BitIOS {
  84. fileprivate static var include32 = false
  85. static func set() {
  86. include32 = true
  87. }
  88. }