Package.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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.42.0"
  32. ),
  33. .package(
  34. url: "https://github.com/apple/swift-nio-http2.git",
  35. from: "1.24.1"
  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. url: "https://github.com/apple/swift-protobuf.git",
  47. from: "1.20.2"
  48. ),
  49. .package(
  50. url: "https://github.com/apple/swift-log.git",
  51. from: "1.4.4"
  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.23.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 grpcSwiftPlugin: Target = .plugin(
  156. name: "GRPCSwiftPlugin",
  157. capability: .buildTool(),
  158. dependencies: [
  159. .protocGenGRPCSwift,
  160. ]
  161. )
  162. static let grpcTests: Target = .testTarget(
  163. name: "GRPCTests",
  164. dependencies: [
  165. .grpc,
  166. .echoModel,
  167. .echoImplementation,
  168. .helloWorldModel,
  169. .interopTestModels,
  170. .interopTestImplementation,
  171. .grpcSampleData,
  172. .nioCore,
  173. .nioConcurrencyHelpers,
  174. .nioPosix,
  175. .nioTLS,
  176. .nioHTTP1,
  177. .nioHTTP2,
  178. .nioEmbedded,
  179. .nioTransportServices,
  180. .logging,
  181. ].appending(
  182. .nioSSL, if: includeNIOSSL
  183. ),
  184. exclude: [
  185. "Codegen/Normalization/normalization.proto",
  186. ]
  187. )
  188. static let interopTestModels: Target = .target(
  189. name: "GRPCInteroperabilityTestModels",
  190. dependencies: [
  191. .grpc,
  192. .nio,
  193. .protobuf,
  194. ],
  195. exclude: [
  196. "README.md",
  197. "generate.sh",
  198. "src/proto/grpc/testing/empty.proto",
  199. "src/proto/grpc/testing/empty_service.proto",
  200. "src/proto/grpc/testing/messages.proto",
  201. "src/proto/grpc/testing/test.proto",
  202. "unimplemented_call.patch",
  203. ]
  204. )
  205. static let interopTestImplementation: Target = .target(
  206. name: "GRPCInteroperabilityTestsImplementation",
  207. dependencies: [
  208. .grpc,
  209. .interopTestModels,
  210. .nioCore,
  211. .nioPosix,
  212. .nioHTTP1,
  213. .logging,
  214. ].appending(
  215. .nioSSL, if: includeNIOSSL
  216. )
  217. )
  218. static let interopTests: Target = .executableTarget(
  219. name: "GRPCInteroperabilityTests",
  220. dependencies: [
  221. .grpc,
  222. .interopTestImplementation,
  223. .nioCore,
  224. .nioPosix,
  225. .logging,
  226. .argumentParser,
  227. ]
  228. )
  229. static let backoffInteropTest: Target = .executableTarget(
  230. name: "GRPCConnectionBackoffInteropTest",
  231. dependencies: [
  232. .grpc,
  233. .interopTestModels,
  234. .nioCore,
  235. .nioPosix,
  236. .logging,
  237. .argumentParser,
  238. ],
  239. exclude: [
  240. "README.md",
  241. ]
  242. )
  243. static let perfTests: Target = .executableTarget(
  244. name: "GRPCPerformanceTests",
  245. dependencies: [
  246. .grpc,
  247. .grpcSampleData,
  248. .nioCore,
  249. .nioEmbedded,
  250. .nioPosix,
  251. .nioHTTP2,
  252. .argumentParser,
  253. ]
  254. )
  255. static let grpcSampleData: Target = .target(
  256. name: "GRPCSampleData",
  257. dependencies: includeNIOSSL ? [.nioSSL] : [],
  258. exclude: [
  259. "bundle.p12",
  260. ]
  261. )
  262. static let echoModel: Target = .target(
  263. name: "EchoModel",
  264. dependencies: [
  265. .grpc,
  266. .nio,
  267. .protobuf,
  268. ],
  269. path: "Sources/Examples/Echo/Model",
  270. exclude: [
  271. "echo.proto",
  272. ]
  273. )
  274. static let echoImplementation: Target = .target(
  275. name: "EchoImplementation",
  276. dependencies: [
  277. .echoModel,
  278. .grpc,
  279. .nioCore,
  280. .nioHTTP2,
  281. .protobuf,
  282. ],
  283. path: "Sources/Examples/Echo/Implementation"
  284. )
  285. static let echo: Target = .executableTarget(
  286. name: "Echo",
  287. dependencies: [
  288. .grpc,
  289. .echoModel,
  290. .echoImplementation,
  291. .grpcSampleData,
  292. .nioCore,
  293. .nioPosix,
  294. .logging,
  295. .argumentParser,
  296. ].appending(
  297. .nioSSL, if: includeNIOSSL
  298. ),
  299. path: "Sources/Examples/Echo/Runtime"
  300. )
  301. static let helloWorldModel: Target = .target(
  302. name: "HelloWorldModel",
  303. dependencies: [
  304. .grpc,
  305. .nio,
  306. .protobuf,
  307. ],
  308. path: "Sources/Examples/HelloWorld/Model",
  309. exclude: [
  310. "helloworld.proto",
  311. ]
  312. )
  313. static let helloWorldClient: Target = .executableTarget(
  314. name: "HelloWorldClient",
  315. dependencies: [
  316. .grpc,
  317. .helloWorldModel,
  318. .nioCore,
  319. .nioPosix,
  320. .argumentParser,
  321. ],
  322. path: "Sources/Examples/HelloWorld/Client"
  323. )
  324. static let helloWorldServer: Target = .executableTarget(
  325. name: "HelloWorldServer",
  326. dependencies: [
  327. .grpc,
  328. .helloWorldModel,
  329. .nioCore,
  330. .nioPosix,
  331. .argumentParser,
  332. ],
  333. path: "Sources/Examples/HelloWorld/Server"
  334. )
  335. static let routeGuideModel: Target = .target(
  336. name: "RouteGuideModel",
  337. dependencies: [
  338. .grpc,
  339. .nio,
  340. .protobuf,
  341. ],
  342. path: "Sources/Examples/RouteGuide/Model",
  343. exclude: [
  344. "route_guide.proto",
  345. ]
  346. )
  347. static let routeGuideClient: Target = .executableTarget(
  348. name: "RouteGuideClient",
  349. dependencies: [
  350. .grpc,
  351. .routeGuideModel,
  352. .nioCore,
  353. .nioPosix,
  354. .argumentParser,
  355. ],
  356. path: "Sources/Examples/RouteGuide/Client"
  357. )
  358. static let routeGuideServer: Target = .executableTarget(
  359. name: "RouteGuideServer",
  360. dependencies: [
  361. .grpc,
  362. .routeGuideModel,
  363. .nioCore,
  364. .nioConcurrencyHelpers,
  365. .nioPosix,
  366. .argumentParser,
  367. ],
  368. path: "Sources/Examples/RouteGuide/Server"
  369. )
  370. static let packetCapture: Target = .executableTarget(
  371. name: "PacketCapture",
  372. dependencies: [
  373. .grpc,
  374. .echoModel,
  375. .nioCore,
  376. .nioPosix,
  377. .nioExtras,
  378. .argumentParser,
  379. ],
  380. path: "Sources/Examples/PacketCapture",
  381. exclude: [
  382. "README.md",
  383. ]
  384. )
  385. }
  386. // MARK: - Products
  387. extension Product {
  388. static let grpc: Product = .library(
  389. name: grpcProductName,
  390. targets: [grpcTargetName]
  391. )
  392. static let cgrpcZlib: Product = .library(
  393. name: cgrpcZlibProductName,
  394. targets: [cgrpcZlibTargetName]
  395. )
  396. static let protocGenGRPCSwift: Product = .executable(
  397. name: "protoc-gen-grpc-swift",
  398. targets: ["protoc-gen-grpc-swift"]
  399. )
  400. static let grpcSwiftPlugin: Product = .plugin(
  401. name: "GRPCSwiftPlugin",
  402. targets: ["GRPCSwiftPlugin"]
  403. )
  404. }
  405. // MARK: - Package
  406. let package = Package(
  407. name: grpcPackageName,
  408. products: [
  409. .grpc,
  410. .cgrpcZlib,
  411. .protocGenGRPCSwift,
  412. .grpcSwiftPlugin,
  413. ],
  414. dependencies: packageDependencies,
  415. targets: [
  416. // Products
  417. .grpc,
  418. .cgrpcZlib,
  419. .protocGenGRPCSwift,
  420. .grpcSwiftPlugin,
  421. // Tests etc.
  422. .grpcTests,
  423. .interopTestModels,
  424. .interopTestImplementation,
  425. .interopTests,
  426. .backoffInteropTest,
  427. .perfTests,
  428. .grpcSampleData,
  429. // Examples
  430. .echoModel,
  431. .echoImplementation,
  432. .echo,
  433. .helloWorldModel,
  434. .helloWorldClient,
  435. .helloWorldServer,
  436. .routeGuideModel,
  437. .routeGuideClient,
  438. .routeGuideServer,
  439. .packetCapture,
  440. ]
  441. )
  442. extension Array {
  443. func appending(_ element: Element, if condition: Bool) -> [Element] {
  444. if condition {
  445. return self + [element]
  446. } else {
  447. return self
  448. }
  449. }
  450. }