Package.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. ]
  32. let dependencies: [Package.Dependency] = [
  33. .package(
  34. url: "https://github.com/grpc/grpc-swift.git",
  35. from: "2.0.0"
  36. ),
  37. .package(
  38. url: "https://github.com/apple/swift-protobuf.git",
  39. from: "1.28.1"
  40. ),
  41. ]
  42. let defaultSwiftSettings: [SwiftSetting] = [
  43. .swiftLanguageMode(.v6),
  44. .enableUpcomingFeature("ExistentialAny"),
  45. .enableUpcomingFeature("InternalImportsByDefault"),
  46. .enableUpcomingFeature("MemberImportVisibility"),
  47. ]
  48. let targets: [Target] = [
  49. // protoc plugin for grpc-swift
  50. .executableTarget(
  51. name: "protoc-gen-grpc-swift",
  52. dependencies: [
  53. .target(name: "GRPCProtobufCodeGen"),
  54. .product(name: "GRPCCodeGen", package: "grpc-swift"),
  55. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  56. .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
  57. ],
  58. swiftSettings: defaultSwiftSettings
  59. ),
  60. // Runtime serialization components
  61. .target(
  62. name: "GRPCProtobuf",
  63. dependencies: [
  64. .product(name: "GRPCCore", package: "grpc-swift"),
  65. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  66. ],
  67. swiftSettings: defaultSwiftSettings
  68. ),
  69. .testTarget(
  70. name: "GRPCProtobufTests",
  71. dependencies: [
  72. .target(name: "GRPCProtobuf"),
  73. .product(name: "GRPCCore", package: "grpc-swift"),
  74. .product(name: "GRPCInProcessTransport", package: "grpc-swift"),
  75. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  76. ],
  77. swiftSettings: defaultSwiftSettings
  78. ),
  79. // Code generator library for protoc-gen-grpc-swift
  80. .target(
  81. name: "GRPCProtobufCodeGen",
  82. dependencies: [
  83. .product(name: "GRPCCodeGen", package: "grpc-swift"),
  84. .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
  85. ],
  86. swiftSettings: defaultSwiftSettings
  87. ),
  88. .testTarget(
  89. name: "GRPCProtobufCodeGenTests",
  90. dependencies: [
  91. .target(name: "GRPCProtobufCodeGen"),
  92. .product(name: "GRPCCodeGen", package: "grpc-swift"),
  93. .product(name: "SwiftProtobuf", package: "swift-protobuf"),
  94. .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
  95. ],
  96. resources: [
  97. .copy("Generated")
  98. ],
  99. swiftSettings: defaultSwiftSettings
  100. ),
  101. // Code generator build plugin
  102. .plugin(
  103. name: "GRPCProtobufGenerator",
  104. capability: .buildTool(),
  105. dependencies: [
  106. .target(name: "protoc-gen-grpc-swift"),
  107. .product(name: "protoc-gen-swift", package: "swift-protobuf"),
  108. ]
  109. ),
  110. // Code generator SwiftPM command
  111. .plugin(
  112. name: "GRPCProtobufGeneratorCommand",
  113. capability: .command(
  114. intent: .custom(
  115. verb: "generate-grpc-code-from-protos",
  116. description: "Generate Swift code for gRPC services from protobuf definitions."
  117. ),
  118. permissions: [
  119. .writeToPackageDirectory(
  120. reason:
  121. "To write the generated Swift files back into the source directory of the package."
  122. )
  123. ]
  124. ),
  125. dependencies: [
  126. .target(name: "protoc-gen-grpc-swift"),
  127. .product(name: "protoc-gen-swift", package: "swift-protobuf"),
  128. ]
  129. ),
  130. ]
  131. let package = Package(
  132. name: "grpc-swift-protobuf",
  133. platforms: [
  134. .macOS(.v15),
  135. .iOS(.v18),
  136. .tvOS(.v18),
  137. .watchOS(.v11),
  138. .visionOS(.v2),
  139. ],
  140. products: products,
  141. dependencies: dependencies,
  142. targets: targets
  143. )