Package@swift-5.5.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. // swift-tools-version:5.5
  2. /*
  3. * Copyright 2022, 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. // swiftformat puts the next import before the tools version.
  19. // swiftformat:disable:next sortedImports
  20. import class Foundation.ProcessInfo
  21. let grpcPackageName = "grpc-swift"
  22. let grpcProductName = "GRPC"
  23. let cgrpcZlibProductName = "CGRPCZlib"
  24. let grpcTargetName = grpcProductName
  25. let cgrpcZlibTargetName = cgrpcZlibProductName
  26. let includeNIOSSL = ProcessInfo.processInfo.environment["GRPC_NO_NIO_SSL"] == nil
  27. // MARK: - Package Dependencies
  28. let packageDependencies: [Package.Dependency] = [
  29. .package(
  30. url: "https://github.com/apple/swift-nio.git",
  31. from: "2.42.0"
  32. ),
  33. .package(
  34. url: "https://github.com/apple/swift-nio-http2.git",
  35. from: "1.22.0"
  36. ),
  37. .package(
  38. url: "https://github.com/apple/swift-nio-transport-services.git",
  39. from: "1.15.0"
  40. ),
  41. .package(
  42. url: "https://github.com/apple/swift-nio-extras.git",
  43. from: "1.4.0"
  44. ),
  45. .package(
  46. name: "SwiftProtobuf",
  47. url: "https://github.com/apple/swift-protobuf.git",
  48. from: "1.20.2"
  49. ),
  50. .package(
  51. url: "https://github.com/apple/swift-log.git",
  52. from: "1.4.0"
  53. ),
  54. .package(
  55. url: "https://github.com/apple/swift-argument-parser.git",
  56. from: "1.0.0"
  57. ),
  58. ].appending(
  59. .package(
  60. url: "https://github.com/apple/swift-nio-ssl.git",
  61. from: "2.23.0"
  62. ),
  63. if: includeNIOSSL
  64. )
  65. // MARK: - Target Dependencies
  66. extension Target.Dependency {
  67. // Target dependencies; external
  68. static let grpc: Self = .target(name: grpcTargetName)
  69. static let cgrpcZlib: Self = .target(name: cgrpcZlibTargetName)
  70. static let protocGenGRPCSwift: Self = .target(name: "protoc-gen-grpc-swift")
  71. // Target dependencies; internal
  72. static let grpcSampleData: Self = .target(name: "GRPCSampleData")
  73. static let echoModel: Self = .target(name: "EchoModel")
  74. static let echoImplementation: Self = .target(name: "EchoImplementation")
  75. static let helloWorldModel: Self = .target(name: "HelloWorldModel")
  76. static let routeGuideModel: Self = .target(name: "RouteGuideModel")
  77. static let interopTestModels: Self = .target(name: "GRPCInteroperabilityTestModels")
  78. static let interopTestImplementation: Self =
  79. .target(name: "GRPCInteroperabilityTestsImplementation")
  80. // Product dependencies
  81. static let argumentParser: Self = .product(
  82. name: "ArgumentParser",
  83. package: "swift-argument-parser"
  84. )
  85. static let nio: Self = .product(name: "NIO", package: "swift-nio")
  86. static let nioConcurrencyHelpers: Self = .product(
  87. name: "NIOConcurrencyHelpers",
  88. package: "swift-nio"
  89. )
  90. static let nioCore: Self = .product(name: "NIOCore", package: "swift-nio")
  91. static let nioEmbedded: Self = .product(name: "NIOEmbedded", package: "swift-nio")
  92. static let nioExtras: Self = .product(name: "NIOExtras", package: "swift-nio-extras")
  93. static let nioFoundationCompat: Self = .product(name: "NIOFoundationCompat", package: "swift-nio")
  94. static let nioHTTP1: Self = .product(name: "NIOHTTP1", package: "swift-nio")
  95. static let nioHTTP2: Self = .product(name: "NIOHTTP2", package: "swift-nio-http2")
  96. static let nioPosix: Self = .product(name: "NIOPosix", package: "swift-nio")
  97. static let nioSSL: Self = .product(name: "NIOSSL", package: "swift-nio-ssl")
  98. static let nioTLS: Self = .product(name: "NIOTLS", package: "swift-nio")
  99. static let nioTransportServices: Self = .product(
  100. name: "NIOTransportServices",
  101. package: "swift-nio-transport-services"
  102. )
  103. static let logging: Self = .product(name: "Logging", package: "swift-log")
  104. static let protobuf: Self = .product(name: "SwiftProtobuf", package: "SwiftProtobuf")
  105. static let protobufPluginLibrary: Self = .product(
  106. name: "SwiftProtobufPluginLibrary",
  107. package: "SwiftProtobuf"
  108. )
  109. }
  110. // MARK: - Targets
  111. extension Target {
  112. static let grpc: Target = .target(
  113. name: grpcTargetName,
  114. dependencies: [
  115. .cgrpcZlib,
  116. .nio,
  117. .nioCore,
  118. .nioPosix,
  119. .nioEmbedded,
  120. .nioFoundationCompat,
  121. .nioTLS,
  122. .nioTransportServices,
  123. .nioHTTP1,
  124. .nioHTTP2,
  125. .nioExtras,
  126. .logging,
  127. .protobuf,
  128. ].appending(
  129. .nioSSL, if: includeNIOSSL
  130. ),
  131. path: "Sources/GRPC"
  132. )
  133. static let cgrpcZlib: Target = .target(
  134. name: cgrpcZlibTargetName,
  135. path: "Sources/CGRPCZlib",
  136. linkerSettings: [
  137. .linkedLibrary("z"),
  138. ]
  139. )
  140. static let protocGenGRPCSwift: Target = .executableTarget(
  141. name: "protoc-gen-grpc-swift",
  142. dependencies: [
  143. .protobuf,
  144. .protobufPluginLibrary,
  145. ],
  146. exclude: [
  147. "README.md",
  148. ]
  149. )
  150. static let grpcTests: Target = .testTarget(
  151. name: "GRPCTests",
  152. dependencies: [
  153. .grpc,
  154. .echoModel,
  155. .echoImplementation,
  156. .helloWorldModel,
  157. .interopTestModels,
  158. .interopTestImplementation,
  159. .grpcSampleData,
  160. .nioCore,
  161. .nioConcurrencyHelpers,
  162. .nioPosix,
  163. .nioTLS,
  164. .nioHTTP1,
  165. .nioHTTP2,
  166. .nioEmbedded,
  167. .nioTransportServices,
  168. .logging,
  169. ].appending(
  170. .nioSSL, if: includeNIOSSL
  171. ),
  172. exclude: [
  173. "Codegen/Normalization/normalization.proto",
  174. ]
  175. )
  176. static let interopTestModels: Target = .target(
  177. name: "GRPCInteroperabilityTestModels",
  178. dependencies: [
  179. .grpc,
  180. .nio,
  181. .protobuf,
  182. ],
  183. exclude: [
  184. "README.md",
  185. "generate.sh",
  186. "src/proto/grpc/testing/empty.proto",
  187. "src/proto/grpc/testing/empty_service.proto",
  188. "src/proto/grpc/testing/messages.proto",
  189. "src/proto/grpc/testing/test.proto",
  190. "unimplemented_call.patch",
  191. ]
  192. )
  193. static let interopTestImplementation: Target = .target(
  194. name: "GRPCInteroperabilityTestsImplementation",
  195. dependencies: [
  196. .grpc,
  197. .interopTestModels,
  198. .nioCore,
  199. .nioPosix,
  200. .nioHTTP1,
  201. .logging,
  202. ].appending(
  203. .nioSSL, if: includeNIOSSL
  204. )
  205. )
  206. static let interopTests: Target = .executableTarget(
  207. name: "GRPCInteroperabilityTests",
  208. dependencies: [
  209. .grpc,
  210. .interopTestImplementation,
  211. .nioCore,
  212. .nioPosix,
  213. .logging,
  214. .argumentParser,
  215. ]
  216. )
  217. static let backoffInteropTest: Target = .executableTarget(
  218. name: "GRPCConnectionBackoffInteropTest",
  219. dependencies: [
  220. .grpc,
  221. .interopTestModels,
  222. .nioCore,
  223. .nioPosix,
  224. .logging,
  225. .argumentParser,
  226. ],
  227. exclude: [
  228. "README.md",
  229. ]
  230. )
  231. static let perfTests: Target = .executableTarget(
  232. name: "GRPCPerformanceTests",
  233. dependencies: [
  234. .grpc,
  235. .grpcSampleData,
  236. .nioCore,
  237. .nioEmbedded,
  238. .nioPosix,
  239. .nioHTTP2,
  240. .argumentParser,
  241. ]
  242. )
  243. static let grpcSampleData: Target = .target(
  244. name: "GRPCSampleData",
  245. dependencies: includeNIOSSL ? [.nioSSL] : [],
  246. exclude: [
  247. "bundle.p12",
  248. ]
  249. )
  250. static let echoModel: Target = .target(
  251. name: "EchoModel",
  252. dependencies: [
  253. .grpc,
  254. .nio,
  255. .protobuf,
  256. ],
  257. path: "Sources/Examples/Echo/Model",
  258. exclude: [
  259. "echo.proto",
  260. ]
  261. )
  262. static let echoImplementation: Target = .target(
  263. name: "EchoImplementation",
  264. dependencies: [
  265. .echoModel,
  266. .grpc,
  267. .nioCore,
  268. .nioHTTP2,
  269. .protobuf,
  270. ],
  271. path: "Sources/Examples/Echo/Implementation"
  272. )
  273. static let echo: Target = .executableTarget(
  274. name: "Echo",
  275. dependencies: [
  276. .grpc,
  277. .echoModel,
  278. .echoImplementation,
  279. .grpcSampleData,
  280. .nioCore,
  281. .nioPosix,
  282. .logging,
  283. .argumentParser,
  284. ].appending(
  285. .nioSSL, if: includeNIOSSL
  286. ),
  287. path: "Sources/Examples/Echo/Runtime"
  288. )
  289. static let helloWorldModel: Target = .target(
  290. name: "HelloWorldModel",
  291. dependencies: [
  292. .grpc,
  293. .nio,
  294. .protobuf,
  295. ],
  296. path: "Sources/Examples/HelloWorld/Model",
  297. exclude: [
  298. "helloworld.proto",
  299. ]
  300. )
  301. static let helloWorldClient: Target = .executableTarget(
  302. name: "HelloWorldClient",
  303. dependencies: [
  304. .grpc,
  305. .helloWorldModel,
  306. .nioCore,
  307. .nioPosix,
  308. .argumentParser,
  309. ],
  310. path: "Sources/Examples/HelloWorld/Client"
  311. )
  312. static let helloWorldServer: Target = .executableTarget(
  313. name: "HelloWorldServer",
  314. dependencies: [
  315. .grpc,
  316. .helloWorldModel,
  317. .nioCore,
  318. .nioPosix,
  319. .argumentParser,
  320. ],
  321. path: "Sources/Examples/HelloWorld/Server"
  322. )
  323. static let routeGuideModel: Target = .target(
  324. name: "RouteGuideModel",
  325. dependencies: [
  326. .grpc,
  327. .nio,
  328. .protobuf,
  329. ],
  330. path: "Sources/Examples/RouteGuide/Model",
  331. exclude: [
  332. "route_guide.proto",
  333. ]
  334. )
  335. static let routeGuideClient: Target = .executableTarget(
  336. name: "RouteGuideClient",
  337. dependencies: [
  338. .grpc,
  339. .routeGuideModel,
  340. .nioCore,
  341. .nioPosix,
  342. .argumentParser,
  343. ],
  344. path: "Sources/Examples/RouteGuide/Client"
  345. )
  346. static let routeGuideServer: Target = .executableTarget(
  347. name: "RouteGuideServer",
  348. dependencies: [
  349. .grpc,
  350. .routeGuideModel,
  351. .nioCore,
  352. .nioConcurrencyHelpers,
  353. .nioPosix,
  354. .argumentParser,
  355. ],
  356. path: "Sources/Examples/RouteGuide/Server"
  357. )
  358. static let packetCapture: Target = .executableTarget(
  359. name: "PacketCapture",
  360. dependencies: [
  361. .grpc,
  362. .echoModel,
  363. .nioCore,
  364. .nioPosix,
  365. .nioExtras,
  366. .argumentParser,
  367. ],
  368. path: "Sources/Examples/PacketCapture",
  369. exclude: [
  370. "README.md",
  371. ]
  372. )
  373. }
  374. // MARK: - Products
  375. extension Product {
  376. static let grpc: Product = .library(
  377. name: grpcProductName,
  378. targets: [grpcTargetName]
  379. )
  380. static let cgrpcZlib: Product = .library(
  381. name: cgrpcZlibProductName,
  382. targets: [cgrpcZlibTargetName]
  383. )
  384. static let protocGenGRPCSwift: Product = .executable(
  385. name: "protoc-gen-grpc-swift",
  386. targets: ["protoc-gen-grpc-swift"]
  387. )
  388. }
  389. // MARK: - Package
  390. let package = Package(
  391. name: grpcPackageName,
  392. products: [
  393. .grpc,
  394. .cgrpcZlib,
  395. .protocGenGRPCSwift,
  396. ],
  397. dependencies: packageDependencies,
  398. targets: [
  399. // Products
  400. .grpc,
  401. .cgrpcZlib,
  402. .protocGenGRPCSwift,
  403. // Tests etc.
  404. .grpcTests,
  405. .interopTestModels,
  406. .interopTestImplementation,
  407. .interopTests,
  408. .backoffInteropTest,
  409. .perfTests,
  410. .grpcSampleData,
  411. // Examples
  412. .echoModel,
  413. .echoImplementation,
  414. .echo,
  415. .helloWorldModel,
  416. .helloWorldClient,
  417. .helloWorldServer,
  418. .routeGuideModel,
  419. .routeGuideClient,
  420. .routeGuideServer,
  421. .packetCapture,
  422. ]
  423. )
  424. extension Array {
  425. func appending(_ element: Element, if condition: Bool) -> [Element] {
  426. if condition {
  427. return self + [element]
  428. } else {
  429. return self
  430. }
  431. }
  432. }