Package.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // swift-tools-version: 6.0
  2. /*
  3. * Copyright 2024, gRPC Authors All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import PackageDescription
  18. let products: [Product] = [
  19. .library(
  20. name: "GRPCProtobuf",
  21. targets: ["GRPCProtobuf"]
  22. ),
  23. .executable(
  24. name: "protoc-gen-grpc-swift",
  25. targets: ["protoc-gen-grpc-swift"]
  26. ),
  27. .plugin(
  28. name: "GRPCProtobufGenerator",
  29. targets: ["GRPCProtobufGenerator"]
  30. ),
  31. .plugin(
  32. name: "generate-grpc-code-from-protos",
  33. targets: ["generate-grpc-code-from-protos"]
  34. ),
  35. ]
  36. let dependencies: [Package.Dependency] = [
  37. .package(
  38. url: "https://github.com/grpc/grpc-swift.git",
  39. from: "2.1.0"
  40. ),
  41. .package(
  42. url: "https://github.com/apple/swift-protobuf.git",
  43. from: "1.28.1"
  44. ),
  45. ]
  46. let defaultSwiftSettings: [SwiftSetting] = [
  47. .swiftLanguageMode(.v6),
  48. .enableUpcomingFeature("ExistentialAny"),
  49. .enableUpcomingFeature("InternalImportsByDefault"),
  50. .enableUpcomingFeature("MemberImportVisibility"),
  51. ]
  52. let targets: [Target] = [
  53. // protoc plugin for grpc-swift
  54. .executableTarget(
  55. name: "protoc-gen-grpc-swift",
  56. dependencies: [
  57. .target(name: "GRPCProtobufCodeGen"),
  58. .product(name: "GRPCCodeGen", package: "grpc-swift"),
  59. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  60. .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
  61. ],
  62. swiftSettings: defaultSwiftSettings
  63. ),
  64. // Runtime serialization components
  65. .target(
  66. name: "GRPCProtobuf",
  67. dependencies: [
  68. .product(name: "GRPCCore", package: "grpc-swift"),
  69. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  70. ],
  71. swiftSettings: defaultSwiftSettings
  72. ),
  73. .testTarget(
  74. name: "GRPCProtobufTests",
  75. dependencies: [
  76. .target(name: "GRPCProtobuf"),
  77. .product(name: "GRPCCore", package: "grpc-swift"),
  78. .product(name: "GRPCInProcessTransport", package: "grpc-swift"),
  79. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  80. ],
  81. swiftSettings: defaultSwiftSettings
  82. ),
  83. // Code generator library for protoc-gen-grpc-swift
  84. .target(
  85. name: "GRPCProtobufCodeGen",
  86. dependencies: [
  87. .product(name: "GRPCCodeGen", package: "grpc-swift"),
  88. .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
  89. ],
  90. swiftSettings: defaultSwiftSettings
  91. ),
  92. .testTarget(
  93. name: "GRPCProtobufCodeGenTests",
  94. dependencies: [
  95. .target(name: "GRPCProtobufCodeGen"),
  96. .product(name: "GRPCCodeGen", package: "grpc-swift"),
  97. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  98. .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
  99. ],
  100. resources: [
  101. .copy("Generated")
  102. ],
  103. swiftSettings: defaultSwiftSettings
  104. ),
  105. // Code generator build plugin
  106. .plugin(
  107. name: "GRPCProtobufGenerator",
  108. capability: .buildTool(),
  109. dependencies: [
  110. .target(name: "protoc-gen-grpc-swift"),
  111. .product(name: "protoc-gen-swift", package: "swift-protobuf"),
  112. ]
  113. ),
  114. // Code generator SwiftPM command
  115. .plugin(
  116. name: "generate-grpc-code-from-protos",
  117. capability: .command(
  118. intent: .custom(
  119. verb: "generate-grpc-code-from-protos",
  120. description: "Generate Swift code for gRPC services from protobuf definitions."
  121. ),
  122. permissions: [
  123. .writeToPackageDirectory(
  124. reason:
  125. "To write the generated Swift files back into the source directory of the package."
  126. )
  127. ]
  128. ),
  129. dependencies: [
  130. .target(name: "protoc-gen-grpc-swift"),
  131. .product(name: "protoc-gen-swift", package: "swift-protobuf"),
  132. ],
  133. path: "Plugins/GRPCProtobufGeneratorCommand"
  134. ),
  135. ]
  136. let package = Package(
  137. name: "grpc-swift-protobuf",
  138. platforms: [
  139. .macOS(.v15),
  140. .iOS(.v18),
  141. .tvOS(.v18),
  142. .watchOS(.v11),
  143. .visionOS(.v2),
  144. ],
  145. products: products,
  146. dependencies: dependencies,
  147. targets: targets
  148. )