Package.swift 11 KB

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