TargetPlatform.swift 3.1 KB

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