Package.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // swift-tools-version:5.10
  2. // Package.swift
  3. //
  4. // Copyright (c) 2014 - 2018 Apple Inc. and the project authors
  5. // Licensed under Apache License v2.0 with Runtime Library Exception
  6. //
  7. // See LICENSE.txt for license information:
  8. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  9. //
  10. import PackageDescription
  11. // Including protoc as a binary artifact can cause build issues in some environments. As a
  12. // temporary measure offer an opt-out by setting PROTOBUF_NO_PROTOC=true.
  13. let includeProtoc: Bool
  14. if let noProtoc = Context.environment["PROTOBUF_NO_PROTOC"] {
  15. includeProtoc = !(noProtoc.lowercased() == "true" || noProtoc == "1")
  16. } else {
  17. includeProtoc = true
  18. }
  19. let package = Package(
  20. name: "SwiftProtobuf",
  21. products: [
  22. .executable(
  23. name: "protoc-gen-swift",
  24. targets: ["protoc-gen-swift"]
  25. ),
  26. .library(
  27. name: "SwiftProtobuf",
  28. targets: ["SwiftProtobuf"]
  29. ),
  30. .library(
  31. name: "SwiftProtobufPluginLibrary",
  32. targets: ["SwiftProtobufPluginLibrary"]
  33. ),
  34. .plugin(
  35. name: "SwiftProtobufPlugin",
  36. targets: ["SwiftProtobufPlugin"]
  37. ),
  38. ],
  39. targets: [
  40. .target(
  41. name: "SwiftProtobuf",
  42. exclude: ["CMakeLists.txt"],
  43. resources: [.copy("PrivacyInfo.xcprivacy")],
  44. swiftSettings: .packageSettings
  45. ),
  46. .target(
  47. name: "SwiftProtobufPluginLibrary",
  48. dependencies: ["SwiftProtobuf"],
  49. exclude: ["CMakeLists.txt"],
  50. resources: [.copy("PrivacyInfo.xcprivacy")],
  51. swiftSettings: .packageSettings
  52. ),
  53. .target(
  54. name: "SwiftProtobufTestHelpers",
  55. dependencies: ["SwiftProtobuf"],
  56. swiftSettings: .packageSettings
  57. ),
  58. .executableTarget(
  59. name: "protoc-gen-swift",
  60. dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobuf"],
  61. exclude: ["CMakeLists.txt"],
  62. swiftSettings: .packageSettings
  63. ),
  64. .executableTarget(
  65. name: "Conformance",
  66. dependencies: ["SwiftProtobuf"],
  67. exclude: ["failure_list_swift.txt", "text_format_failure_list_swift.txt"],
  68. swiftSettings: .packageSettings
  69. ),
  70. .plugin(
  71. name: "SwiftProtobufPlugin",
  72. capability: .buildTool(),
  73. dependencies: ["protoc-gen-swift"]
  74. ),
  75. .testTarget(
  76. name: "SwiftProtobufTests",
  77. dependencies: ["SwiftProtobuf"],
  78. swiftSettings: .packageSettings
  79. ),
  80. .testTarget(
  81. name: "SwiftProtobufPluginLibraryTests",
  82. dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobufTestHelpers"],
  83. swiftSettings: .packageSettings
  84. ),
  85. .testTarget(
  86. name: "protoc-gen-swiftTests",
  87. dependencies: ["protoc-gen-swift", "SwiftProtobufTestHelpers"],
  88. swiftSettings: .packageSettings
  89. ),
  90. ],
  91. swiftLanguageVersions: [.v5]
  92. )
  93. if includeProtoc {
  94. package.products.append(
  95. .executable(
  96. name: "protoc",
  97. targets: ["protoc"]
  98. )
  99. )
  100. package.targets.append(
  101. .binaryTarget(
  102. name: "protoc",
  103. url:
  104. "https://github.com/apple/swift-protobuf/releases/download/protoc-artifactbundle-v31.1/protoc-31.1.artifactbundle.zip",
  105. checksum: "f18bf2cfbbebd83133a4c29733b01871e3afdc73c102d62949a841d4f9bab86f"
  106. )
  107. )
  108. if let target = package.targets.first(where: { $0.name == "SwiftProtobufPlugin" }) {
  109. target.dependencies.append("protoc")
  110. }
  111. }
  112. // Settings for every Swift target in this package, like project-level settings
  113. // in an Xcode project.
  114. extension Array where Element == PackageDescription.SwiftSetting {
  115. static var packageSettings: Self {
  116. [
  117. .enableExperimentalFeature("StrictConcurrency=complete"),
  118. .enableUpcomingFeature("ExistentialAny"),
  119. ]
  120. }
  121. }