Package.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. ].appending(
  195. .nioSSL, if: includeNIOSSL
  196. ),
  197. exclude: [
  198. "Codegen/Normalization/normalization.proto",
  199. "Codegen/Serialization/echo.grpc.reflection.txt",
  200. ]
  201. )
  202. static let grpcCoreTests: Target = .testTarget(
  203. name: "GRPCCoreTests",
  204. dependencies: [
  205. .grpcCore,
  206. ]
  207. )
  208. static let interopTestModels: Target = .target(
  209. name: "GRPCInteroperabilityTestModels",
  210. dependencies: [
  211. .grpc,
  212. .nio,
  213. .protobuf,
  214. ],
  215. exclude: [
  216. "README.md",
  217. "generate.sh",
  218. "src/proto/grpc/testing/empty.proto",
  219. "src/proto/grpc/testing/empty_service.proto",
  220. "src/proto/grpc/testing/messages.proto",
  221. "src/proto/grpc/testing/test.proto",
  222. "unimplemented_call.patch",
  223. ]
  224. )
  225. static let interopTestImplementation: Target = .target(
  226. name: "GRPCInteroperabilityTestsImplementation",
  227. dependencies: [
  228. .grpc,
  229. .interopTestModels,
  230. .nioCore,
  231. .nioPosix,
  232. .nioHTTP1,
  233. .logging,
  234. ].appending(
  235. .nioSSL, if: includeNIOSSL
  236. )
  237. )
  238. static let interopTests: Target = .executableTarget(
  239. name: "GRPCInteroperabilityTests",
  240. dependencies: [
  241. .grpc,
  242. .interopTestImplementation,
  243. .nioCore,
  244. .nioPosix,
  245. .logging,
  246. .argumentParser,
  247. ]
  248. )
  249. static let backoffInteropTest: Target = .executableTarget(
  250. name: "GRPCConnectionBackoffInteropTest",
  251. dependencies: [
  252. .grpc,
  253. .interopTestModels,
  254. .nioCore,
  255. .nioPosix,
  256. .logging,
  257. .argumentParser,
  258. ],
  259. exclude: [
  260. "README.md",
  261. ]
  262. )
  263. static let perfTests: Target = .executableTarget(
  264. name: "GRPCPerformanceTests",
  265. dependencies: [
  266. .grpc,
  267. .grpcSampleData,
  268. .nioCore,
  269. .nioEmbedded,
  270. .nioPosix,
  271. .nioHTTP2,
  272. .argumentParser,
  273. ]
  274. )
  275. static let grpcSampleData: Target = .target(
  276. name: "GRPCSampleData",
  277. dependencies: includeNIOSSL ? [.nioSSL] : [],
  278. exclude: [
  279. "bundle.p12",
  280. ]
  281. )
  282. static let echoModel: Target = .target(
  283. name: "EchoModel",
  284. dependencies: [
  285. .grpc,
  286. .nio,
  287. .protobuf,
  288. ],
  289. path: "Sources/Examples/Echo/Model",
  290. exclude: [
  291. "echo.proto",
  292. ]
  293. )
  294. static let echoImplementation: Target = .target(
  295. name: "EchoImplementation",
  296. dependencies: [
  297. .echoModel,
  298. .grpc,
  299. .nioCore,
  300. .nioHTTP2,
  301. .protobuf,
  302. ],
  303. path: "Sources/Examples/Echo/Implementation"
  304. )
  305. static let echo: Target = .executableTarget(
  306. name: "Echo",
  307. dependencies: [
  308. .grpc,
  309. .echoModel,
  310. .echoImplementation,
  311. .grpcSampleData,
  312. .nioCore,
  313. .nioPosix,
  314. .logging,
  315. .argumentParser,
  316. ].appending(
  317. .nioSSL, if: includeNIOSSL
  318. ),
  319. path: "Sources/Examples/Echo/Runtime"
  320. )
  321. static let helloWorldModel: Target = .target(
  322. name: "HelloWorldModel",
  323. dependencies: [
  324. .grpc,
  325. .nio,
  326. .protobuf,
  327. ],
  328. path: "Sources/Examples/HelloWorld/Model",
  329. exclude: [
  330. "helloworld.proto",
  331. ]
  332. )
  333. static let helloWorldClient: Target = .executableTarget(
  334. name: "HelloWorldClient",
  335. dependencies: [
  336. .grpc,
  337. .helloWorldModel,
  338. .nioCore,
  339. .nioPosix,
  340. .argumentParser,
  341. ],
  342. path: "Sources/Examples/HelloWorld/Client"
  343. )
  344. static let helloWorldServer: Target = .executableTarget(
  345. name: "HelloWorldServer",
  346. dependencies: [
  347. .grpc,
  348. .helloWorldModel,
  349. .nioCore,
  350. .nioPosix,
  351. .argumentParser,
  352. ],
  353. path: "Sources/Examples/HelloWorld/Server"
  354. )
  355. static let routeGuideModel: Target = .target(
  356. name: "RouteGuideModel",
  357. dependencies: [
  358. .grpc,
  359. .nio,
  360. .protobuf,
  361. ],
  362. path: "Sources/Examples/RouteGuide/Model",
  363. exclude: [
  364. "route_guide.proto",
  365. ]
  366. )
  367. static let routeGuideClient: Target = .executableTarget(
  368. name: "RouteGuideClient",
  369. dependencies: [
  370. .grpc,
  371. .routeGuideModel,
  372. .nioCore,
  373. .nioPosix,
  374. .argumentParser,
  375. ],
  376. path: "Sources/Examples/RouteGuide/Client"
  377. )
  378. static let routeGuideServer: Target = .executableTarget(
  379. name: "RouteGuideServer",
  380. dependencies: [
  381. .grpc,
  382. .routeGuideModel,
  383. .nioCore,
  384. .nioConcurrencyHelpers,
  385. .nioPosix,
  386. .argumentParser,
  387. ],
  388. path: "Sources/Examples/RouteGuide/Server"
  389. )
  390. static let packetCapture: Target = .executableTarget(
  391. name: "PacketCapture",
  392. dependencies: [
  393. .grpc,
  394. .echoModel,
  395. .nioCore,
  396. .nioPosix,
  397. .nioExtras,
  398. .argumentParser,
  399. ],
  400. path: "Sources/Examples/PacketCapture",
  401. exclude: [
  402. "README.md",
  403. ]
  404. )
  405. static let reflectionService: Target = .target(
  406. name: "GRPCReflectionService",
  407. dependencies: [
  408. .grpc,
  409. .nio,
  410. .protobuf,
  411. ],
  412. path: "Sources/GRPCReflectionService",
  413. exclude: [
  414. "Model/reflection.proto",
  415. ]
  416. )
  417. }
  418. // MARK: - Products
  419. extension Product {
  420. static let grpc: Product = .library(
  421. name: grpcProductName,
  422. targets: [grpcTargetName]
  423. )
  424. static let cgrpcZlib: Product = .library(
  425. name: cgrpcZlibProductName,
  426. targets: [cgrpcZlibTargetName]
  427. )
  428. static let protocGenGRPCSwift: Product = .executable(
  429. name: "protoc-gen-grpc-swift",
  430. targets: ["protoc-gen-grpc-swift"]
  431. )
  432. static let grpcSwiftPlugin: Product = .plugin(
  433. name: "GRPCSwiftPlugin",
  434. targets: ["GRPCSwiftPlugin"]
  435. )
  436. }
  437. // MARK: - Package
  438. let package = Package(
  439. name: grpcPackageName,
  440. products: [
  441. .grpc,
  442. .cgrpcZlib,
  443. .protocGenGRPCSwift,
  444. .grpcSwiftPlugin,
  445. ],
  446. dependencies: packageDependencies,
  447. targets: [
  448. // Products
  449. .grpc,
  450. .cgrpcZlib,
  451. .protocGenGRPCSwift,
  452. .grpcSwiftPlugin,
  453. .reflectionService,
  454. // Tests etc.
  455. .grpcTests,
  456. .interopTestModels,
  457. .interopTestImplementation,
  458. .interopTests,
  459. .backoffInteropTest,
  460. .perfTests,
  461. .grpcSampleData,
  462. // Examples
  463. .echoModel,
  464. .echoImplementation,
  465. .echo,
  466. .helloWorldModel,
  467. .helloWorldClient,
  468. .helloWorldServer,
  469. .routeGuideModel,
  470. .routeGuideClient,
  471. .routeGuideServer,
  472. .packetCapture,
  473. // v2
  474. .grpcCore,
  475. // v2 tests
  476. .grpcCoreTests,
  477. ]
  478. )
  479. extension Array {
  480. func appending(_ element: Element, if condition: Bool) -> [Element] {
  481. if condition {
  482. return self + [element]
  483. } else {
  484. return self
  485. }
  486. }
  487. }