Package.swift 13 KB

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